From 81878a6f7996c4b491d3a726925159ffc5742ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Tue, 22 Dec 2020 12:19:25 +0100 Subject: [PATCH] Fix of #5537 - GUI_App::post_init could be in some cases called before GUI_App::init_openg when GCode viewer is used. The solution adds a status flag to GUI_App::init_openg and ensures that GUI_App::post_init isn't called before initialization in GUI_App::init_openg is done. --- src/slic3r/GUI/GUI_App.cpp | 13 +++++++++++++ src/slic3r/GUI/GUI_App.hpp | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index a49509db1..3e82d6a3c 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -669,7 +669,13 @@ wxGLContext* GUI_App::init_glcontext(wxGLCanvas& canvas) bool GUI_App::init_opengl() { +#ifdef __linux__ + bool status = m_opengl_mgr.init_gl(); + m_opengl_initialized = true; + return status; +#else return m_opengl_mgr.init_gl(); +#endif } void GUI_App::init_app_config() @@ -916,7 +922,14 @@ bool GUI_App::on_init_inner() this->obj_manipul()->update_if_dirty(); static bool update_gui_after_init = true; + + // An ugly solution to GH #5537 in which GUI_App::init_opengl (normally called from events wxEVT_PAINT + // and wxEVT_SET_FOCUS before GUI_App::post_init is called) wasn't called before GUI_App::post_init and OpenGL wasn't initialized. +#ifdef __linux__ + if (update_gui_after_init && m_opengl_initialized) { +#else if (update_gui_after_init) { +#endif update_gui_after_init = false; #ifdef WIN32 this->mainframe->register_win32_callbacks(); diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index db9f743cc..8aceb7a69 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -109,6 +109,9 @@ private: bool m_app_conf_exists{ false }; EAppMode m_app_mode{ EAppMode::Editor }; bool m_is_recreating_gui{ false }; +#ifdef __linux__ + bool m_opengl_initialized{ false }; +#endif wxColour m_color_label_modified; wxColour m_color_label_sys; @@ -251,7 +254,7 @@ public: RemovableDriveManager* removable_drive_manager() { return m_removable_drive_manager.get(); } OtherInstanceMessageHandler* other_instance_message_handler() { return m_other_instance_message_handler.get(); } wxSingleInstanceChecker* single_instance_checker() {return m_single_instance_checker.get();} - + void init_single_instance_checker(const std::string &name, const std::string &path); void set_instance_hash (const size_t hash) { m_instance_hash_int = hash; m_instance_hash_string = std::to_string(hash); } std::string get_instance_hash_string () { return m_instance_hash_string; }