jcs
/amend
/amendments
/113
browser+main: Hopefully fix a bug that was crashing after committing
Under heavy memory pressure, List Manager seems to close our
custom resource and then re-open it, clearing the custom addr
we set during setup. Make sure it's still alive before doing
an update or we'll jump to NULL.
jcs made amendment 113 about 1 year ago
--- browser.c Mon Feb 6 10:22:39 2023
+++ browser.c Mon Apr 17 15:23:07 2023
@@ -53,6 +53,7 @@ void browser_discard_changes(struct browser *browser);
void browser_edit_amendment(struct browser *browser);
Pattern fill_pattern;
+Handle amendment_list_ldef_h = NULL;
void
browser_idle(struct focusable *focusable, EventRecord *event)
@@ -176,6 +177,13 @@ browser_init(struct repo *repo)
bounds.top = bounds.left = PADDING;
bounds.left = bounds.right + PADDING;
bounds.right = browser->win->portRect.right - SCROLLBAR_WIDTH - PADDING;
+
+ if (amendment_list_ldef_h == NULL) {
+ /* dynamically patch list LDEF to point to our custom function */
+ amendment_list_ldef_h = xGetResource('LDEF', AMENDMENT_LDEF_ID);
+ HLock(amendment_list_ldef_h);
+ ((tCodeStub *)*amendment_list_ldef_h)->addr = &amendment_list_ldef;
+ }
cell_size.v = (FontHeight(geneva, 9) * 2) + 2;
browser->amendment_list = LNew(&bounds, &data_bounds, cell_size,
@@ -554,6 +562,7 @@ browser_update(struct focusable *focusable, EventRecor
struct browser *browser = (struct browser *)focusable->cookie;
Rect r;
short what = -1;
+ Handle t;
if (event != NULL)
what = event->what;
@@ -581,6 +590,19 @@ browser_update(struct focusable *focusable, EventRecor
InsetRect(&r, -1, -1);
FillRect(&r, white);
FrameRect(&r);
+
+ /*
+ * Under heavy memory pressure, List Manager seems to close our
+ * custom resource and then re-open it, clearing the custom addr
+ * we set during setup. Make sure it's still alive before doing
+ * an update or we'll jump to NULL.
+ */
+ if (*amendment_list_ldef_h == NULL ||
+ ((tCodeStub *)*amendment_list_ldef_h)->addr == 0) {
+ amendment_list_ldef_h = xGetResource('LDEF', AMENDMENT_LDEF_ID);
+ HLock(amendment_list_ldef_h);
+ ((tCodeStub *)*amendment_list_ldef_h)->addr = &amendment_list_ldef;
+ }
LUpdate(browser->win->visRgn, browser->amendment_list);
TextFont(DIFF_BUTTON_FONT);
--- main.c Thu Nov 10 09:33:36 2022
+++ main.c Wed Mar 29 11:56:25 2023
@@ -26,7 +26,6 @@
#include "util.h"
MenuHandle apple_menu, file_menu, edit_menu, repo_menu, amendment_menu;
-Handle amendment_list_ldef_h;
bool quitting = false;
bool handle_menu(long menu_id);
@@ -69,13 +68,6 @@ main(void)
menu_defaults();
DrawMenuBar();
- /* dynamically patch list LDEF to point to our *_list_ldef funcs */
- amendment_list_ldef_h = GetResource('LDEF', AMENDMENT_LDEF_ID);
- if (!amendment_list_ldef_h)
- err(1, "Can't find amendment list LDEF %d", AMENDMENT_LDEF_ID);
- HLock(amendment_list_ldef_h);
- ((tCodeStub *)*amendment_list_ldef_h)->addr = &amendment_list_ldef;
-
/* see if we were started by double-clicking a .repo file */
CountAppFiles(&finder_action, &finder_count);
@@ -150,17 +142,15 @@ main(void)
break;
case updateEvt:
event_win = (WindowPtr)event.message;
-
- GetPort(&old_port);
- SetPort(event_win);
- BeginUpdate(event_win);
-
focusable = focusable_find(event_win);
- if (focusable && focusable->update)
+ if (focusable && focusable->update) {
+ GetPort(&old_port);
+ SetPort(event_win);
+ BeginUpdate(event_win);
focusable->update(focusable, &event);
-
- EndUpdate(event_win);
- SetPort(old_port);
+ EndUpdate(event_win);
+ SetPort(old_port);
+ }
break;
case activateEvt:
break;