allocate application on heap instead of stack and delete it
This prevents problems with Vulkan debug layers that don't like Vulkan calls to happen during C++ app shutdown.
This commit is contained in:
@@ -5,14 +5,14 @@
|
||||
#include "sdl2.h"
|
||||
#include "ImGui/imgui_impl_sdl.h"
|
||||
|
||||
Example_ImGui exampleImGui;
|
||||
Example_ImGui* exampleImGui;
|
||||
|
||||
int sdl_loop()
|
||||
{
|
||||
bool quit = false;
|
||||
while (!quit)
|
||||
{
|
||||
exampleImGui.Run();
|
||||
exampleImGui->Run();
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)){
|
||||
switch(event.type){
|
||||
@@ -26,13 +26,13 @@ int sdl_loop()
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
// Tells the engine to reload window configuration (size and dpi)
|
||||
exampleImGui.SetWindow(exampleImGui.window);
|
||||
exampleImGui->SetWindow(exampleImGui->window);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST: //TODO
|
||||
exampleImGui.is_window_active = false;
|
||||
exampleImGui->is_window_active = false;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
exampleImGui.is_window_active = true;
|
||||
exampleImGui->is_window_active = true;
|
||||
if (wi::shadercompiler::GetRegisteredShaderCount() > 0)
|
||||
{
|
||||
std::thread([] {
|
||||
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
|
||||
// TODO: Place code here.
|
||||
|
||||
wi::arguments::Parse(argc, argv);
|
||||
|
||||
exampleImGui = new Example_ImGui();
|
||||
sdl2::sdlsystem_ptr_t system = sdl2::make_sdlsystem(SDL_INIT_EVERYTHING | SDL_INIT_EVENTS);
|
||||
if (*system) {
|
||||
wilog_error("Error creating SDL2 system");
|
||||
@@ -85,10 +85,10 @@ int main(int argc, char *argv[])
|
||||
wilog_error("Error creating window");
|
||||
}
|
||||
|
||||
exampleImGui.SetWindow(window.get());
|
||||
exampleImGui->SetWindow(window.get());
|
||||
|
||||
int ret = sdl_loop();
|
||||
|
||||
delete exampleImGui;
|
||||
SDL_Quit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
HINSTANCE hInst; // current instance
|
||||
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
|
||||
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
|
||||
Example_ImGui example_imgui;
|
||||
Example_ImGui* example_imgui;
|
||||
|
||||
// Forward declarations of functions included in this code module:
|
||||
ATOM MyRegisterClass(HINSTANCE hInstance);
|
||||
@@ -28,6 +28,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
|
||||
example_imgui = new Example_ImGui();
|
||||
// TODO: Place code here.
|
||||
|
||||
BOOL dpi_success = SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||
@@ -59,7 +60,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
}
|
||||
else {
|
||||
|
||||
example_imgui.Run();
|
||||
example_imgui->Run();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -115,8 +116,8 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
example_imgui.allow_hdr = false; // Imgui doesn't support HDR
|
||||
example_imgui.SetWindow(hWnd);
|
||||
example_imgui->allow_hdr = false; // Imgui doesn't support HDR
|
||||
example_imgui->SetWindow(hWnd);
|
||||
|
||||
ShowWindow(hWnd, nCmdShow);
|
||||
UpdateWindow(hWnd);
|
||||
@@ -163,8 +164,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
break;
|
||||
case WM_SIZE:
|
||||
case WM_DPICHANGED:
|
||||
if (example_imgui.is_window_active)
|
||||
example_imgui.SetWindow(hWnd);
|
||||
if (example_imgui->is_window_active)
|
||||
example_imgui->SetWindow(hWnd);
|
||||
break;
|
||||
case WM_CHAR:
|
||||
switch (wParam)
|
||||
@@ -186,10 +187,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
wi::input::rawinput::ParseMessage((void*)lParam);
|
||||
break;
|
||||
case WM_KILLFOCUS:
|
||||
example_imgui.is_window_active = false;
|
||||
example_imgui->is_window_active = false;
|
||||
break;
|
||||
case WM_SETFOCUS:
|
||||
example_imgui.is_window_active = true;
|
||||
example_imgui->is_window_active = true;
|
||||
break;
|
||||
case WM_PAINT:
|
||||
{
|
||||
@@ -205,6 +206,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
delete example_imgui;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user