Skip to content

Commit cc4d587

Browse files
committed
Fix viewports crashing
1 parent 722362e commit cc4d587

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

Engine/src/engine/AppWindow.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ void AppWindow::AddViewport(const sf::VideoMode& mode, std::string_view title, u
102102
window->setFramerateLimit(30);
103103
bool res = ImGui::SFML::Init(*window, true);
104104
LOGDEBUGF("[AddViewport] ImGui SFML Init result: {}", res);
105+
if (!res)
106+
return;
107+
105108
viewports.push_back(std::move(window));
106109
}
107110

@@ -150,6 +153,14 @@ std::queue<std::filesystem::path>& AppWindow::GetDroppedFilesQueue()
150153
return dropped_files_queue;
151154
}
152155

156+
void AppWindow::CleanUpViewports()
157+
{
158+
for (auto& v : viewports)
159+
v->close();
160+
161+
viewports.clear();
162+
}
163+
153164
#ifdef _WIN32
154165
LRESULT CALLBACK AppWindow::WndProc(HWND handle, UINT message, WPARAM wparam, LPARAM lparam)
155166
{

Engine/src/engine/AppWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class ENGINE_API AppWindow : public sf::RenderWindow
2828

2929
static std::queue<std::filesystem::path>& GetDroppedFilesQueue();
3030

31+
static void CleanUpViewports();
32+
3133
#ifdef _WIN32
3234
static inline LONG_PTR orginal_wnd_proc = NULL;
3335
static LRESULT CALLBACK WndProc(HWND handle, UINT message, WPARAM wparam, LPARAM lparam);

Engine/src/engine/Engine.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,13 @@ void Render(AppWindow& window)
350350

351351
// imgui
352352
render_ui(ImGui::GetCurrentContext());
353+
AppWindow::UpdateViewports(event_callback);
353354

354355
for (auto& obj : Scene::current_scene.objects_all)
355356
for (auto& [name, script] : obj->GetAttachedScripts())
356357
script->OnImGui(obj.get(), ImGui::GetCurrentContext());
357358

358359
ImGui::SFML::Render(window);
359-
AppWindow::UpdateViewports(event_callback);
360360
#else
361361
#if defined(TOAD_EDITOR) || !defined(NDEBUG)
362362
for (auto& obj : Scene::current_scene.objects_all)
@@ -535,6 +535,8 @@ void CleanUp()
535535

536536
LOGDEBUG("closing window");
537537
GetWindow().close();
538+
539+
AppWindow::CleanUpViewports();
538540
}
539541

540542
Camera& GetEditorCamera()

0 commit comments

Comments
 (0)