commit 396f5edb07ecfa5d87ab29733bb03713696912c5
parent 633e1a4c1ad40351a68816c913029c41a64bfb44
Author: falkTX <falktx@falktx.com>
Date: Sun, 23 May 2021 22:45:52 +0100
Make Application::quit() thread-safe
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/dgl/src/ApplicationPrivateData.cpp b/dgl/src/ApplicationPrivateData.cpp
@@ -32,6 +32,7 @@ Application::PrivateData::PrivateData(const bool standalone)
standalone ? PUGL_WORLD_THREADS : 0x0)),
isStandalone(standalone),
isQuitting(false),
+ isQuittingInNextCycle(false),
isStarting(true),
visibleWindows(0),
windows(),
@@ -92,6 +93,12 @@ void Application::PrivateData::oneWindowClosed() noexcept
void Application::PrivateData::idle(const uint timeoutInMs)
{
+ if (isQuittingInNextCycle)
+ {
+ quit();
+ isQuittingInNextCycle = false;
+ }
+
if (world != nullptr)
{
const double timeoutInSeconds = timeoutInMs != 0
@@ -112,6 +119,12 @@ void Application::PrivateData::quit()
{
DISTRHO_SAFE_ASSERT_RETURN(isStandalone,);
+ if (! isQuittingInNextCycle)
+ {
+ isQuittingInNextCycle = true;
+ return;
+ }
+
isQuitting = true;
#ifndef DPF_TEST_APPLICATION_CPP
diff --git a/dgl/src/ApplicationPrivateData.hpp b/dgl/src/ApplicationPrivateData.hpp
@@ -39,6 +39,9 @@ struct Application::PrivateData {
/** Whether the applicating is about to quit, or already stopped. Defaults to false. */
bool isQuitting;
+ /** Helper for safely close everything from main thread. */
+ bool isQuittingInNextCycle;
+
/** Whether the applicating is starting up, that is, no windows have been made visible yet. Defaults to true. */
bool isStarting;