Patch Update - Fix Release

FIX :

~ Modifie l'ordre des shutdown
+ Ajout de Mutex pour éviter de release et de render la frame en même temp
- Suppression d'un shutdown oublié de ImGui dans systeme class
This commit is contained in:
CatChow0 2024-04-12 16:19:18 +02:00
parent 117d31d788
commit 42226741ce
7 changed files with 137 additions and 27 deletions

View File

@ -88,32 +88,52 @@ bool SystemClass::Initialize()
void SystemClass::Shutdown() void SystemClass::Shutdown()
{ {
logger.Log("Shutting down system class", __FILE__, __LINE__);
std::lock_guard<std::mutex> guard(renderMutex);
// Shutdown imgui
if (m_imguiManager)
{
logger.Log("Shutting down imgui manager", __FILE__, __LINE__);
m_imguiManager->Shutdown();
delete m_imguiManager;
m_imguiManager = 0;
logger.Log("Imgui manager shut down", __FILE__, __LINE__);
}
// Release the application class object. // Release the application class object.
if (m_Application) if (m_Application)
{ {
logger.Log("Shutting down application", __FILE__, __LINE__);
m_Application->Shutdown(); m_Application->Shutdown();
delete m_Application; delete m_Application;
m_Application = 0; m_Application = 0;
logger.Log("Application shut down", __FILE__, __LINE__);
} }
// Release the input object. // Release the input object.
if (m_Input) if (m_Input)
{ {
logger.Log("Shutting down input", __FILE__, __LINE__);
delete m_Input; delete m_Input;
m_Input = 0; m_Input = 0;
logger.Log("Input shut down", __FILE__, __LINE__);
} }
// Shutdown imgui
if (m_imguiManager)
{
m_imguiManager->Shutdown();
delete m_imguiManager;
m_imguiManager = 0;
}
// Shutdown the window. // Shutdown the window.
ShutdownWindows(); ShutdownWindows();
logger.Log("System class shut down", __FILE__, __LINE__);
return; return;
} }
@ -134,14 +154,21 @@ void SystemClass::Run()
// Handle the windows messages. // Handle the windows messages.
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{ {
TranslateMessage(&msg); if(msg.message == WM_QUIT)
DispatchMessage(&msg); {
done = true;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} }
// If windows signals to end the application then exit out. // If windows signals to end the application then exit out.
if (msg.message == WM_QUIT) if (m_Application != nullptr && m_Application->GetShouldQuit())
{ {
logger.Log("WM_QUIT message received", __FILE__, __LINE__); logger.Log("Received quit signal from application", __FILE__, __LINE__);
done = true; done = true;
} }
else else
@ -162,6 +189,8 @@ void SystemClass::Run()
bool SystemClass::Frame() bool SystemClass::Frame()
{ {
std::lock_guard<std::mutex> guard(renderMutex);
bool result; bool result;
// Do the input frame processing. // Do the input frame processing.
@ -172,6 +201,14 @@ bool SystemClass::Frame()
return false; return false;
} }
// Render ImGui
result = m_imguiManager->ImGuiWidgetRenderer(m_Application);
if (!result)
{
logger.Log("Failed to render ImGui widgets", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Do the frame processing for the application class object. // Do the frame processing for the application class object.
result = m_Application->Frame(m_Input); result = m_Application->Frame(m_Input);
if (!result) if (!result)
@ -180,9 +217,6 @@ bool SystemClass::Frame()
return false; return false;
} }
// Render ImGui
m_imguiManager->ImGuiWidgetRenderer(m_Application);
return true; return true;
} }
@ -267,6 +301,12 @@ LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam
DragFinish(hDrop); DragFinish(hDrop);
return 0; return 0;
} }
case WM_CLOSE:
{
logger.Log("WM_CLOSE message received", __FILE__, __LINE__);
m_Application->SetShouldQuit(true);
return 0;
}
// Any other messages send to the default message handler as our application won't make use of them. // Any other messages send to the default message handler as our application won't make use of them.
default: default:
{ {
@ -365,6 +405,8 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
void SystemClass::ShutdownWindows() void SystemClass::ShutdownWindows()
{ {
logger.Log("Shutting down windows", __FILE__, __LINE__);
logger.Log("Shutting down the windows", __FILE__, __LINE__); logger.Log("Shutting down the windows", __FILE__, __LINE__);
// Show the mouse cursor. // Show the mouse cursor.
ShowCursor(true); ShowCursor(true);
@ -386,11 +428,6 @@ void SystemClass::ShutdownWindows()
// Release the pointer to this class. // Release the pointer to this class.
ApplicationHandle = NULL; ApplicationHandle = NULL;
//Releases COM references that ImGui was given on setup
ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
return; return;
} }

View File

@ -1,6 +1,6 @@
#include "applicationclass.h" #include "applicationclass.h"
ApplicationClass::ApplicationClass() ApplicationClass::ApplicationClass() : m_ShouldQuit(false)
{ {
m_Direct3D = 0; m_Direct3D = 0;
m_Camera = 0; m_Camera = 0;
@ -306,131 +306,191 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
void ApplicationClass::Shutdown() void ApplicationClass::Shutdown()
{ {
logger.Log("Shutting down application class", __FILE__, __LINE__);
// Release the shader manager object. // Release the shader manager object.
if (m_ShaderManager) if (m_ShaderManager)
{ {
logger.Log("Releasing the shader manager object", __FILE__, __LINE__);
m_ShaderManager->Shutdown(); m_ShaderManager->Shutdown();
delete m_ShaderManager; delete m_ShaderManager;
m_ShaderManager = 0; m_ShaderManager = 0;
logger.Log("Shader manager object released", __FILE__, __LINE__);
} }
// Release the frustum class object. // Release the frustum class object.
if (m_Frustum) if (m_Frustum)
{ {
logger.Log("Releasing the frustum class object", __FILE__, __LINE__);
delete m_Frustum; delete m_Frustum;
m_Frustum = 0; m_Frustum = 0;
logger.Log("Frustum class object released", __FILE__, __LINE__);
} }
// Release the display plane object. // Release the display plane object.
if (m_DisplayPlane) if (m_DisplayPlane)
{ {
logger.Log("Releasing the display plane object", __FILE__, __LINE__);
m_DisplayPlane->Shutdown(); m_DisplayPlane->Shutdown();
delete m_DisplayPlane; delete m_DisplayPlane;
m_DisplayPlane = 0; m_DisplayPlane = 0;
logger.Log("Display plane object released", __FILE__, __LINE__);
} }
// Release the position object. // Release the position object.
if (m_Position) if (m_Position)
{ {
logger.Log("Releasing the position object", __FILE__, __LINE__);
delete m_Position; delete m_Position;
m_Position = 0; m_Position = 0;
logger.Log("Position object released", __FILE__, __LINE__);
} }
// Release the model list object. // Release the model list object.
if (m_ModelList) if (m_ModelList)
{ {
logger.Log("Releasing the model list object", __FILE__, __LINE__);
m_ModelList->Shutdown(); m_ModelList->Shutdown();
delete m_ModelList; delete m_ModelList;
m_ModelList = 0; m_ModelList = 0;
logger.Log("Model list object released", __FILE__, __LINE__);
} }
// Release the text objects for the render count string. // Release the text objects for the render count string.
if (m_RenderCountString) if (m_RenderCountString)
{ {
logger.Log("Releasing the render count string object", __FILE__, __LINE__);
m_RenderCountString->Shutdown(); m_RenderCountString->Shutdown();
delete m_RenderCountString; delete m_RenderCountString;
m_RenderCountString = 0; m_RenderCountString = 0;
logger.Log("Render count string object released", __FILE__, __LINE__);
} }
// Release the text objects for the mouse strings. // Release the text objects for the mouse strings.
if (m_MouseStrings) if (m_MouseStrings)
{ {
logger.Log("Releasing the mouse strings", __FILE__, __LINE__);
m_MouseStrings[0].Shutdown(); m_MouseStrings[0].Shutdown();
m_MouseStrings[1].Shutdown(); m_MouseStrings[1].Shutdown();
m_MouseStrings[2].Shutdown(); m_MouseStrings[2].Shutdown();
delete[] m_MouseStrings; delete[] m_MouseStrings;
m_MouseStrings = 0; m_MouseStrings = 0;
logger.Log("Mouse strings released", __FILE__, __LINE__);
} }
// Release the text object for the fps string. // Release the text object for the fps string.
if (m_FpsString) if (m_FpsString)
{ {
logger.Log("Releasing the fps string object", __FILE__, __LINE__);
m_FpsString->Shutdown(); m_FpsString->Shutdown();
delete m_FpsString; delete m_FpsString;
m_FpsString = 0; m_FpsString = 0;
logger.Log("Fps string object released", __FILE__, __LINE__);
} }
// Release the fps object. // Release the fps object.
if (m_Fps) if (m_Fps)
{ {
logger.Log("Releasing the fps object", __FILE__, __LINE__);
delete m_Fps; delete m_Fps;
m_Fps = 0; m_Fps = 0;
logger.Log("Fps object released", __FILE__, __LINE__);
} }
// Release the font object. // Release the font object.
if (m_Font) if (m_Font)
{ {
logger.Log("Releasing the font object", __FILE__, __LINE__);
m_Font->Shutdown(); m_Font->Shutdown();
delete m_Font; delete m_Font;
m_Font = 0; m_Font = 0;
logger.Log("Font object released", __FILE__, __LINE__);
} }
// Release the font shader object. // Release the font shader object.
if (m_FontShader) if (m_FontShader)
{ {
logger.Log("Releasing the font shader object", __FILE__, __LINE__);
m_FontShader->Shutdown(); m_FontShader->Shutdown();
delete m_FontShader; delete m_FontShader;
m_FontShader = 0; m_FontShader = 0;
logger.Log("Font shader object released", __FILE__, __LINE__);
} }
// Release the timer object. // Release the timer object.
if (m_Timer) if (m_Timer)
{ {
logger.Log("Releasing the timer object", __FILE__, __LINE__);
delete m_Timer; delete m_Timer;
m_Timer = 0; m_Timer = 0;
logger.Log("Timer object released", __FILE__, __LINE__);
} }
// Release the sprite object. // Release the sprite object.
if (m_Sprite) if (m_Sprite)
{ {
logger.Log("Releasing the sprite object", __FILE__, __LINE__);
m_Sprite->Shutdown(); m_Sprite->Shutdown();
delete m_Sprite; delete m_Sprite;
m_Sprite = 0; m_Sprite = 0;
logger.Log("Sprite object released", __FILE__, __LINE__);
} }
for (auto light : m_Lights) for (auto light : m_Lights)
{ {
logger.Log("Releasing the light object", __FILE__, __LINE__);
if (light) if (light)
{ {
delete light; delete light;
light = 0; light = 0;
} }
logger.Log("Light object released", __FILE__, __LINE__);
} }
// Release the light object. // Release the light object.
if (m_Light) if (m_Light)
{ {
logger.Log("Releasing the light object", __FILE__, __LINE__);
delete m_Light; delete m_Light;
m_Light = 0; m_Light = 0;
logger.Log("Light object released", __FILE__, __LINE__);
} }
// Release the model object. // Release the model object.
if (m_Model) if (m_Model)
{ {
logger.Log("Releasing the model object", __FILE__, __LINE__);
m_Model->Shutdown(); m_Model->Shutdown();
delete m_Model; delete m_Model;
m_Model = 0; m_Model = 0;
logger.Log("Model object released", __FILE__, __LINE__);
} }
} }
@ -460,7 +520,8 @@ bool ApplicationClass::Frame(InputClass* Input)
// Check if the user pressed escape and wants to exit the application. // Check if the user pressed escape and wants to exit the application.
if (Input->IsEscapePressed()) if (Input->IsEscapePressed())
{ {
return false; logger.Log("User pressed escape, exiting application", __FILE__, __LINE__);
m_ShouldQuit = true;
} }
// Get the location of the mouse from the input object, // Get the location of the mouse from the input object,

View File

@ -29,6 +29,7 @@
#include "rendertextureclass.h" #include "rendertextureclass.h"
#include "displayplaneclass.h" #include "displayplaneclass.h"
#include "reflectionshaderclass.h" #include "reflectionshaderclass.h"
#include "systemclass.h"
///////////// /////////////
@ -75,14 +76,14 @@ public:
XMVECTOR GetLightPosition(int index); XMVECTOR GetLightPosition(int index);
XMVECTOR GetLightColor(int index); XMVECTOR GetLightColor(int index);
void SetLightPosition(int index, XMVECTOR color); void SetLightPosition(int index, XMVECTOR color);
void SetLightColor(int index, XMVECTOR color); void SetLightColor(int index, XMVECTOR color);
void DeleteLight(int index); void DeleteLight(int index);
std::vector<LightClass*> GetLights() const { return m_Lights; }; std::vector<LightClass*> GetLights() const { return m_Lights; };
bool GetShouldQuit() const { return m_ShouldQuit; };
void SetShouldQuit(bool shouldQuit) { m_ShouldQuit = shouldQuit; };
private: private:
bool Render(float, float, float, float, float); bool Render(float, float, float, float, float);
bool UpdateMouseStrings(int, int, bool); bool UpdateMouseStrings(int, int, bool);
@ -158,6 +159,12 @@ private :
// ------------------- LOGGER ---------------------- // // ------------------- LOGGER ---------------------- //
// ------------------------------------------------- // // ------------------------------------------------- //
Logger logger; Logger logger;
// ------------------------------------------------- //
// ------------------- OTHER ----------------------- //
// ------------------------------------------------- //
bool m_ShouldQuit;
}; };
#endif #endif

View File

@ -15,6 +15,6 @@ Pos=60,60
Size=342,82 Size=342,82
[Window][Light] [Window][Light]
Pos=95,296 Pos=62,180
Size=345,230 Size=345,230

View File

@ -201,7 +201,7 @@ void imguiManager::WidgetTerrainWindow(ApplicationClass* app)
ImGui::End(); ImGui::End();
} }
void imguiManager::ImGuiWidgetRenderer(ApplicationClass* app) bool imguiManager::ImGuiWidgetRenderer(ApplicationClass* app)
{ {
// Start the Dear ImGui frame // Start the Dear ImGui frame
NewFrame(); NewFrame();
@ -255,6 +255,8 @@ void imguiManager::ImGuiWidgetRenderer(ApplicationClass* app)
Render(); Render();
app->GetDirect3D()->m_swapChain->Present(0, NULL); app->GetDirect3D()->m_swapChain->Present(0, NULL);
return true;
} }
void imguiManager::WidgetLightWindow(ApplicationClass* app) void imguiManager::WidgetLightWindow(ApplicationClass* app)

View File

@ -32,7 +32,7 @@ public:
void WidgetTerrainWindow(ApplicationClass* app); void WidgetTerrainWindow(ApplicationClass* app);
void WidgetLightWindow(ApplicationClass* app); void WidgetLightWindow(ApplicationClass* app);
void ImGuiWidgetRenderer(ApplicationClass* app); bool ImGuiWidgetRenderer(ApplicationClass* app);
private : private :
bool showObjectWindow = false; bool showObjectWindow = false;

View File

@ -8,6 +8,7 @@
#include "inputclass.h" #include "inputclass.h"
#include "applicationclass.h" #include "applicationclass.h"
#include "imguiManager.h" #include "imguiManager.h"
#include <mutex>
#include "resources.h" #include "resources.h"
class SystemClass class SystemClass
@ -42,6 +43,8 @@ private:
int m_initialWindowHeight; int m_initialWindowHeight;
bool m_isDirect3DInitialized; bool m_isDirect3DInitialized;
bool m_isResizing = false; bool m_isResizing = false;
std::mutex renderMutex;
}; };