Window can close properly (with the exception of scene graph dtor crash)

This commit is contained in:
Brandon Mak 2022-10-02 01:13:04 +08:00
parent 8a6ef1fc2d
commit 9fabb7d672
5 changed files with 27 additions and 8 deletions

View File

@ -73,6 +73,11 @@ namespace SHADE
renderContext.SetIsResized(true);
});
window->RegisterWindowCloseCallback([&](void)
{
renderContext.SetWindowIsDead(true);
}
);
// Create graphics queue
graphicsQueue = device->GetQueue(SH_Q_FAM::GRAPHICS, 0);
transferQueue = device->GetQueue(SH_Q_FAM::TRANSFER, 0);
@ -213,7 +218,7 @@ namespace SHADE
/***************************************************************************/
void SHGraphicsSystem::Run(double) noexcept
{
if (window->IsMinimized())
if (window->IsMinimized() || renderContext.GetWindowIsDead())
return;
if (renderContext.GetResized())
@ -344,7 +349,7 @@ namespace SHADE
/***************************************************************************/
void SHGraphicsSystem::BeginRender()
{
if (window->IsMinimized())
if (window->IsMinimized() || renderContext.GetWindowIsDead())
return;
// Finalise all batches
@ -393,7 +398,7 @@ namespace SHADE
/***************************************************************************/
void SHGraphicsSystem::EndRender()
{
if (window->IsMinimized())
if (window->IsMinimized() || renderContext.GetWindowIsDead())
return;
if (renderContext.GetResized())
@ -535,7 +540,7 @@ namespace SHADE
void SHGraphicsSystem::HandleResize(void) noexcept
{
if (window->IsMinimized())
if (window->IsMinimized() || renderContext.GetWindowIsDead())
return;
auto windowDims = window->GetWindowSize();

View File

@ -168,6 +168,11 @@ namespace SHADE
isResized = resized;
}
void SHRenderContext::SetWindowIsDead(bool dead) noexcept
{
windowIsDead = dead;
}
/***************************************************************************/
/*!
@ -209,4 +214,9 @@ namespace SHADE
return b;
}
bool SHRenderContext::GetWindowIsDead(void) const noexcept
{
return windowIsDead;
}
}

View File

@ -36,6 +36,7 @@ namespace SHADE
uint32_t currentFrame;
bool isResized{ false };
bool windowIsDead {false};
public:
SHRenderContext(void) noexcept;
@ -51,13 +52,15 @@ namespace SHADE
bool WaitForFence (void) noexcept;
void ResetFence (void) noexcept;
void SetIsResized (bool resized) noexcept;
void SetIsResized (bool resized) noexcept;
void SetWindowIsDead (bool dead) noexcept;
SHPerFrameData& GetCurrentFrameData(void) noexcept;
SHPerFrameData& GetFrameData (uint32_t index) noexcept;
uint32_t GetCurrentFrame (void) const noexcept;
bool GetResized(void) noexcept;
bool GetResized (void) noexcept;
bool GetResizeAndReset (void) noexcept;
bool GetWindowIsDead (void) const noexcept;
};
}

View File

@ -272,7 +272,7 @@ namespace SHADE
windowResizeCallbacks.erase(callbackid);
}
SHWindow::CALLBACKID SHWindow::RegisterWindowCloseCallback(WindowResizeCallbackFn windowCloseCallback)
SHWindow::CALLBACKID SHWindow::RegisterWindowCloseCallback(WindowCloseCallbackFn windowCloseCallback)
{
windowCloseCallbacks.try_emplace(windowResizeCallbackCount, windowCloseCallback);
return windowCloseCallbackCount++;
@ -388,6 +388,7 @@ namespace SHADE
void SHWindow::OnDestroy()
{
OnClose();
this->Destroy();
}

View File

@ -126,7 +126,7 @@ namespace SHADE
CALLBACKID RegisterWindowSizeCallback(WindowResizeCallbackFn);
void UnregisterWindowSizeCallback(CALLBACKID const& callbackid);
CALLBACKID RegisterWindowCloseCallback(WindowResizeCallbackFn);
CALLBACKID RegisterWindowCloseCallback(WindowCloseCallbackFn);
void UnregisterWindowCloseCallback(CALLBACKID const& callbackid);
bool IsMinimized() const { return wndData.isMinimised; }