diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 808567c23..b08d25368 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1706,6 +1706,9 @@ float GLCanvas3D::get_collapse_toolbar_height() return collapse_toolbar.is_enabled() ? collapse_toolbar.get_height() : 0; } +bool GLCanvas3D::make_current_for_postinit() { + return _set_current(); +} void GLCanvas3D::render(bool only_init) { diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 47354060a..82a20b2d1 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -1043,6 +1043,8 @@ public: // If the Z screen space coordinate is not provided, a depth buffer value is substituted. Vec3d _mouse_to_3d(const Point& mouse_pos, float* z = nullptr); + bool make_current_for_postinit(); + private: bool _is_shown_on_screen() const; diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 316797f82..a66d6faf5 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "libslic3r/Utils.hpp" #include "libslic3r/Model.hpp" @@ -1016,6 +1017,16 @@ void GUI_App::post_init() mainframe->select_tab(size_t(MainFrame::tp3DEditor)); plater_->select_view_3D("3D"); //BBS init the opengl resource here +#ifdef __linux__ + if (!plater_->canvas3D()->get_wxglcanvas()->IsShownOnScreen() || + !plater_->canvas3D()->make_current_for_postinit()) { + /* The canvas3d didn't actually exist (and therefore, there is + * no current EGL context) -- try again later, I guess. + */ + m_post_initialized = false; + return; + } +#endif Size canvas_size = plater_->canvas3D()->get_canvas_size(); wxGetApp().imgui()->set_display_size(static_cast(canvas_size.get_width()), static_cast(canvas_size.get_height())); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", start to init opengl";