From 072cc4482b20626b4b5ae46ae7d50e899c7a7924 Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 27 Jul 2023 11:17:53 +0200 Subject: [PATCH] Better handling of pugl world creation failures Signed-off-by: falkTX --- dgl/src/ApplicationPrivateData.cpp | 8 +++----- dgl/src/WindowPrivateData.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dgl/src/ApplicationPrivateData.cpp b/dgl/src/ApplicationPrivateData.cpp index 0d3323db..3eb05bc9 100644 --- a/dgl/src/ApplicationPrivateData.cpp +++ b/dgl/src/ApplicationPrivateData.cpp @@ -160,17 +160,15 @@ void Application::PrivateData::quit() double Application::PrivateData::getTime() const { - DISTRHO_SAFE_ASSERT_RETURN(world != nullptr, 0.0); - - return puglGetTime(world); + return world != nullptr ? puglGetTime(world) : 0.0; } void Application::PrivateData::setClassName(const char* const name) { - DISTRHO_SAFE_ASSERT_RETURN(world != nullptr,); DISTRHO_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',); - puglSetClassName(world, name); + if (world != nullptr) + puglSetClassName(world, name); } // -------------------------------------------------------------------------------------------------------------------- diff --git a/dgl/src/WindowPrivateData.cpp b/dgl/src/WindowPrivateData.cpp index 089cfd83..f879dfdf 100644 --- a/dgl/src/WindowPrivateData.cpp +++ b/dgl/src/WindowPrivateData.cpp @@ -66,7 +66,8 @@ static double getScaleFactorFromParent(const PuglView* const view) static PuglView* puglNewViewWithTransientParent(PuglWorld* const world, PuglView* const transientParentView) { - DISTRHO_SAFE_ASSERT_RETURN(world != nullptr, nullptr); + if (world == nullptr) + return nullptr; if (PuglView* const view = puglNewView(world)) { @@ -79,7 +80,8 @@ static PuglView* puglNewViewWithTransientParent(PuglWorld* const world, PuglView static PuglView* puglNewViewWithParentWindow(PuglWorld* const world, const uintptr_t parentWindowHandle) { - DISTRHO_SAFE_ASSERT_RETURN(world != nullptr, nullptr); + if (world == nullptr) + return nullptr; if (PuglView* const view = puglNewView(world)) { @@ -433,7 +435,7 @@ void Window::PrivateData::idleCallback() bool Window::PrivateData::addIdleCallback(IdleCallback* const callback, const uint timerFrequencyInMs) { - if (ignoreIdleCallbacks) + if (ignoreIdleCallbacks || view == nullptr) return false; if (timerFrequencyInMs == 0) @@ -447,7 +449,7 @@ bool Window::PrivateData::addIdleCallback(IdleCallback* const callback, const ui bool Window::PrivateData::removeIdleCallback(IdleCallback* const callback) { - if (ignoreIdleCallbacks) + if (ignoreIdleCallbacks || view == nullptr) return false; if (std::find(appData->idleCallbacks.begin(),