Fixed an random crash on start on Linux (#14052)

This commit is contained in:
SoftFever
2026-06-05 17:00:35 +08:00
committed by GitHub
parent 2ad6beed32
commit 4088a36095

View File

@@ -61,6 +61,7 @@
#include <wx/dialog.h> #include <wx/dialog.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/splash.h> #include <wx/splash.h>
#include <wx/weakref.h>
#include <wx/fontutil.h> #include <wx/fontutil.h>
#include <wx/glcanvas.h> #include <wx/glcanvas.h>
#include <wx/utils.h> #include <wx/utils.h>
@@ -349,6 +350,17 @@ public:
} }
} }
// Orca: keep the splash alive until it is explicitly destroyed.
// wxSplashScreen installs an application-wide event filter that calls
// Close() (which Destroy()s the window) on ANY key press or mouse-button
// down. Since startup keeps the splash up across the whole load_presets()
// and main-window-creation phase, a single stray click/keypress would
// destroy it while on_init_inner() still holds the pointer, causing an
// intermittent use-after-free crash. Override the filter to a no-op so the
// splash can only be removed via the explicit Destroy() once the main frame
// is shown.
int FilterEvent(wxEvent& /*event*/) override { return wxEventFilter::Event_Skip; }
void scale_font(wxFont& font, float scale) void scale_font(wxFont& font, float scale)
{ {
#ifdef __WXMSW__ #ifdef __WXMSW__
@@ -2763,7 +2775,8 @@ bool GUI_App::on_init_inner()
app_config->set("version", SLIC3R_VERSION); app_config->set("version", SLIC3R_VERSION);
} }
SplashScreen * scrn = nullptr; // Orca: use wxWeakRef to provent wild pointer.
wxWeakRef<SplashScreen> scrn = nullptr;
if (app_config->get("show_splash_screen") == "true") { if (app_config->get("show_splash_screen") == "true") {
// Detect position (display) to show the splash screen // Detect position (display) to show the splash screen
// Now this position is equal to the mainframe position // Now this position is equal to the mainframe position