Skip to content

Commit 5c3589d

Browse files
andyclaude
andcommitted
Organizer: fix 4 null-pointer crashes on cold start (#66)
getResource() can legitimately return null when a resource fails to load (e.g. the data server isn't reachable/ready yet) -- three call sites dereferenced it unconditionally: WxResourceTreeCtrl::loadChildren(), CalcMgr::getTypeAndState(), and CalcMgr::onSelectionChange(). A fourth, different bug in the same chain: CalcMgr::focusOnTree() dereferenced p_contextPanel, which can still be null when the tree control receives a real GTK focus-in event during CalcMgr::Create() itself, before p_contextPanel has been constructed -- same premature-event-during- construction class as the Gateway/GatewayPrefs layout crashes fixed earlier this session, just via focus instead of size events. All four found and fixed one at a time via real, symbol-matched coredumps from a reliable cold-start repro (data server down, ecce-organizer bootstraps it, launches Organizer immediately). Verified: Organizer now survives the full startup sequence cleanly and shows its real login dialog once the data server is reachable, instead of crashing before any window appears. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent ca7b7ad commit 5c3589d

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎src/apps/organizer/CalcMgr.C‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,15 @@ bool CalcMgr::getTypeAndState(WxResourceTreeItemData * itemData,
21652165

21662166
if (itemData != 0) {
21672167
Resource * res = itemData->getResource();
2168+
// getResource() can legitimately return null (e.g. the resource
2169+
// failed to load because the data server wasn't reachable/ready
2170+
// yet) -- confirmed via a real core dump hit on every cold start,
2171+
// in TreeEvtHandler::OnSetFocus() -> onSelectionChange() ->
2172+
// getFileMenu() -> here, same bug shape as the WxResourceTreeCtrl
2173+
// fix alongside this one.
2174+
if (res == 0) {
2175+
return false;
2176+
}
21682177
resType = res->getDescriptor();
21692178
if (resType == 0) {
21702179
return false;
@@ -4868,7 +4877,10 @@ void CalcMgr::onSelectionChange(bool selectInTree)
48684877
}
48694878
else {
48704879
itemData = findNode(p_currentSelection[0], false, true);
4871-
if (itemData && itemData->getResource()->hasAccess()) {
4880+
// getResource() can legitimately be null (e.g. resource failed to
4881+
// load) -- confirmed via a real core dump hit on cold start, same
4882+
// bug shape fixed twice already just above this call chain.
4883+
if (itemData && itemData->getResource() && itemData->getResource()->hasAccess()) {
48724884
bool isProject = (itemData->getResource()->getContentType() ==
48734885
ResourceDescriptor::CT_PROJECT);
48744886
bool isCalculation = (itemData->getResource()->getContentType() ==
@@ -4959,7 +4971,15 @@ void CalcMgr::focusOnTree()
49594971
{
49604972
p_focusOnTree = true;
49614973
onSelectionChange(false);
4962-
p_contextPanel->loseFocus();
4974+
// p_contextPanel can still be null here -- confirmed via a real core
4975+
// dump: the tree control can receive a GTK focus-in event (wired to
4976+
// this via TreeEvtHandler::OnSetFocus()) during CalcMgr::Create()
4977+
// itself, before p_contextPanel has been constructed yet. Same
4978+
// premature-event-during-construction bug class as the Gateway/
4979+
// GatewayPrefs layout crashes fixed earlier this session, just hit
4980+
// via focus instead of size events.
4981+
if (p_contextPanel != 0)
4982+
p_contextPanel->loseFocus();
49634983
}
49644984

49654985

‎src/wxgui/wxtools/WxResourceTreeCtrl.C‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,18 @@ bool WxResourceTreeCtrl::loadChildren(WxResourceTreeItemData * node, bool refres
265265
timer.start();
266266
#endif
267267

268-
vector<Resource *> * children = node->getResource()->getChildren(refresh);
268+
// getResource() can legitimately return null -- confirmed via a real
269+
// core dump, hit during Organizer's own automatic startup tree-load
270+
// (mountEDSIProviders() -> autoOpen() -> findNode() -> here), when the
271+
// resource failed to load (e.g. the data server wasn't reachable/ready
272+
// yet). Previously dereferenced unconditionally.
273+
Resource * resource = node->getResource();
274+
if (resource == 0) {
275+
p_loadingChildren = false;
276+
return false;
277+
}
278+
279+
vector<Resource *> * children = resource->getChildren(refresh);
269280

270281
#ifdef cputimetest
271282
timer.stop();

0 commit comments

Comments
 (0)