Skip to content

Commit

Permalink
Fix crash on open TreeSheets files on MacOS
Browse files Browse the repository at this point in the history
When file is loaded directly via the open protocol on MacOS,
`System::FileUsed(const wxString&, Document*)` had been called before
the app event loop was entered. It thus tried to access the uninitialized
file system watcher which led to a crash.

Fix this by contructing the file system watcher right away.
  • Loading branch information
tobiolo committed Dec 30, 2024
1 parent 81e74a0 commit a592369
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/myapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ struct MyApp : wxApp {
void OnEventLoopEnter(wxEventLoopBase *WXUNUSED(loop)) {
if (!initateventloop) {
initateventloop = true;
frame->AppOnEventLoopEnter();
sys->Init(filename);
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/myframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct MyFrame : wxFrame {
wxTaskBarIcon tbi;
wxMenu *editmenupopup;
wxFileHistory filehistory;
unique_ptr<wxFileSystemWatcher> watcher {nullptr};
unique_ptr<wxFileSystemWatcher> watcher {make_unique<wxFileSystemWatcher>()};
wxAuiNotebook *nb {nullptr};
unique_ptr<wxAuiManager> aui {make_unique<wxAuiManager>(this)};
wxBitmap line_nw;
Expand Down Expand Up @@ -710,14 +710,10 @@ struct MyFrame : wxFrame {

SetFileAssoc(exename);

wxSafeYield();
}

void AppOnEventLoopEnter() {
// Have to do this here, if we do it in the Frame constructor above, it crashes on OS X.
watcher.reset(new wxFileSystemWatcher());
watcher->SetOwner(this);
Connect(wxEVT_FSWATCHER, wxFileSystemWatcherEventHandler(MyFrame::OnFileSystemEvent));

wxSafeYield();
}

~MyFrame() {
Expand Down

0 comments on commit a592369

Please sign in to comment.