@@ -66,8 +66,7 @@ bool Fast3dGui::SupportsViewports() {
6666}
6767
6868void Fast3dGui::HandleWindowEvents (Fast::WindowEvent event) {
69- auto window = Ship::Context::GetInstance ()->GetWindow ();
70- switch (window->GetWindowBackend ()) {
69+ switch (mWindow ->GetWindowBackend ()) {
7170 case WindowBackend::FAST3D_SDL_OPENGL :
7271 case WindowBackend::FAST3D_SDL_METAL :
7372 ImGui_ImplSDL2_ProcessEvent (static_cast <const SDL_Event*>(event.Sdl .Event ));
@@ -87,10 +86,11 @@ void Fast3dGui::HandleWindowEvents(Fast::WindowEvent event) {
8786}
8887
8988void Fast3dGui::ImGuiWMInit () {
90- auto window = Ship::Context::GetInstance ()->GetWindow ();
91- mInterpreter = std::dynamic_pointer_cast<Fast3dWindow>(window)->GetInterpreterWeak ();
89+ mWindow = Ship::Context::GetInstance ()->GetWindow ();
90+ if (auto fast3dWindow = std::dynamic_pointer_cast<Fast3dWindow>(mWindow ))
91+ mInterpreter = fast3dWindow->GetInterpreterWeak ();
9292
93- switch (window ->GetWindowBackend ()) {
93+ switch (mWindow ->GetWindowBackend ()) {
9494 case WindowBackend::FAST3D_SDL_OPENGL :
9595 SDL_SetHint (SDL_HINT_TOUCH_MOUSE_EVENTS , " 1" );
9696 if (Ship::Context::GetInstance ()->GetConsoleVariables ()->GetInteger (CVAR_ALLOW_BACKGROUND_INPUTS , 1 )) {
@@ -118,8 +118,7 @@ void Fast3dGui::ImGuiWMInit() {
118118}
119119
120120void Fast3dGui::ImGuiWMShutdown () {
121- auto window = Ship::Context::GetInstance ()->GetWindow ();
122- switch (window->GetWindowBackend ()) {
121+ switch (mWindow ->GetWindowBackend ()) {
123122#ifdef ENABLE_OPENGL
124123 case WindowBackend::FAST3D_SDL_OPENGL :
125124 ImGui_ImplSDL2_Shutdown ();
@@ -138,11 +137,13 @@ void Fast3dGui::ImGuiWMShutdown() {
138137 default :
139138 break ;
140139 }
140+
141+ mWindow = nullptr ;
141142}
142143
143144void Fast3dGui::ImGuiBackendInit () {
144- auto window = Ship::Context::GetInstance ()->GetWindow ();
145- switch (window ->GetWindowBackend ()) {
145+ mBackendWindow = Ship::Context::GetInstance ()->GetWindow ();
146+ switch (mBackendWindow ->GetWindowBackend ()) {
146147#ifdef ENABLE_OPENGL
147148 case WindowBackend::FAST3D_SDL_OPENGL :
148149#ifdef __APPLE__
@@ -175,8 +176,7 @@ void Fast3dGui::ImGuiBackendInit() {
175176}
176177
177178void Fast3dGui::ImGuiBackendShutdown () {
178- auto window = Ship::Context::GetInstance ()->GetWindow ();
179- switch (window->GetWindowBackend ()) {
179+ switch (mBackendWindow ->GetWindowBackend ()) {
180180#ifdef ENABLE_OPENGL
181181 case WindowBackend::FAST3D_SDL_OPENGL :
182182 ImGui_ImplOpenGL3_Shutdown ();
@@ -195,11 +195,12 @@ void Fast3dGui::ImGuiBackendShutdown() {
195195 default :
196196 break ;
197197 }
198+
199+ mBackendWindow = nullptr ;
198200}
199201
200202void Fast3dGui::ImGuiBackendNewFrame () {
201- auto window = Ship::Context::GetInstance ()->GetWindow ();
202- switch (window->GetWindowBackend ()) {
203+ switch (mBackendWindow ->GetWindowBackend ()) {
203204#ifdef ENABLE_OPENGL
204205 case WindowBackend::FAST3D_SDL_OPENGL :
205206 ImGui_ImplOpenGL3_NewFrame ();
@@ -225,8 +226,7 @@ void Fast3dGui::ImGuiBackendNewFrame() {
225226}
226227
227228void Fast3dGui::ImGuiWMNewFrame () {
228- auto window = Ship::Context::GetInstance ()->GetWindow ();
229- switch (window->GetWindowBackend ()) {
229+ switch (mWindow ->GetWindowBackend ()) {
230230 case WindowBackend::FAST3D_SDL_OPENGL :
231231 case WindowBackend::FAST3D_SDL_METAL :
232232 ImGui_ImplSDL2_NewFrame ();
@@ -242,8 +242,7 @@ void Fast3dGui::ImGuiWMNewFrame() {
242242}
243243
244244void Fast3dGui::ImGuiRenderDrawData (ImDrawData* data) {
245- auto window = Ship::Context::GetInstance ()->GetWindow ();
246- switch (window->GetWindowBackend ()) {
245+ switch (mWindow ->GetWindowBackend ()) {
247246#ifdef ENABLE_OPENGL
248247 case WindowBackend::FAST3D_SDL_OPENGL :
249248 ImGui_ImplOpenGL3_RenderDrawData (data);
@@ -273,9 +272,8 @@ void Fast3dGui::DrawFloatingWindows() {
273272 return ;
274273 }
275274
276- auto window = Ship::Context::GetInstance ()->GetWindow ();
277275 // OpenGL requires extra platform handling for the GL context
278- if (window ->GetWindowBackend () == WindowBackend::FAST3D_SDL_OPENGL && mImpl .Opengl .Context != nullptr ) {
276+ if (mWindow ->GetWindowBackend () == WindowBackend::FAST3D_SDL_OPENGL && mImpl .Opengl .Context != nullptr ) {
279277 // Backup window and context before calling RenderPlatformWindowsDefault
280278 SDL_Window* backupCurrentWindow = SDL_GL_GetCurrentWindow ();
281279 SDL_GLContext backupCurrentContext = SDL_GL_GetCurrentContext ();
0 commit comments