From 0f81b3de2cd0f5c7711b03067d198723b2781d08 Mon Sep 17 00:00:00 2001 From: Pavel Kalian Date: Tue, 4 Jun 2024 18:01:35 -0300 Subject: [PATCH] Protect against trying to deactivate busy spinner when not busy (fix asserts in macOS non-GL) --- gui/src/OCPNPlatform.cpp | 18 ++--------------- model/include/model/base_platform.h | 1 + model/src/base_platform.cpp | 31 ++++++++++++++++++++++++----- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/gui/src/OCPNPlatform.cpp b/gui/src/OCPNPlatform.cpp index 00341bbe09..77affc1494 100644 --- a/gui/src/OCPNPlatform.cpp +++ b/gui/src/OCPNPlatform.cpp @@ -1681,25 +1681,11 @@ bool OCPNPlatform::hasInternalGPS(wxString profile) { //-------------------------------------------------------------------------- void OCPNPlatform::ShowBusySpinner(void) { -#ifdef __ANDROID__ - androidShowBusyIcon(); -#else -#if wxCHECK_VERSION(2, 9, 0) - // if( !::wxIsBusy() ) - { ::wxBeginBusyCursor(); } -#endif -#endif + AbstractPlatform::ShowBusySpinner(); } void OCPNPlatform::HideBusySpinner(void) { -#ifdef __ANDROID__ - androidHideBusyIcon(); -#else -#if wxCHECK_VERSION(2, 9, 0) - // if( ::wxIsBusy() ) - { ::wxEndBusyCursor(); } -#endif -#endif + AbstractPlatform::ShowBusySpinner(); } double OCPNPlatform::GetDisplayDensityFactor() { diff --git a/model/include/model/base_platform.h b/model/include/model/base_platform.h index 20fda8a6ad..a0a4671c6f 100644 --- a/model/include/model/base_platform.h +++ b/model/include/model/base_platform.h @@ -166,6 +166,7 @@ class AbstractPlatform { #endif int m_monitorWidth, m_monitorHeight; bool m_bdisableWindowsDisplayEnum; + static bool m_isBusy; }; class BasePlatform : public AbstractPlatform { diff --git a/model/src/base_platform.cpp b/model/src/base_platform.cpp index 43761ba5d4..fdf3ce39fe 100644 --- a/model/src/base_platform.cpp +++ b/model/src/base_platform.cpp @@ -77,6 +77,8 @@ static const char PATH_SEP = ';'; static const char PATH_SEP = ':'; #endif +bool AbstractPlatform::m_isBusy = false; + static const char* const DEFAULT_XDG_DATA_DIRS = "~/.local/share:/usr/local/share:/usr/share"; @@ -744,17 +746,36 @@ wxString AbstractPlatform::GetPluginDataPath() { return m_pluginDataPath; } - #ifdef __ANDROID__ -void AbstractPlatform::ShowBusySpinner() { androidShowBusyIcon(); } +void AbstractPlatform::ShowBusySpinner() { + if (!m_isBusy) { + androidShowBusyIcon(); + m_isBusy = true; + } +} #else -void AbstractPlatform::ShowBusySpinner() { ::wxBeginBusyCursor(); } +void AbstractPlatform::ShowBusySpinner() { + if (!m_isBusy) { + ::wxBeginBusyCursor(); + m_isBusy = true; + } +} #endif #ifdef __ANDROID__ -void AbstractPlatform::HideBusySpinner() { androidHideBusyIcon(); } +void AbstractPlatform::HideBusySpinner() { + if (m_isBusy) { + androidHideBusyIcon(); + m_isBusy = false; + } +} #else -void AbstractPlatform::HideBusySpinner() { ::wxEndBusyCursor(); } +void AbstractPlatform::HideBusySpinner() { + if (m_isBusy) { + ::wxEndBusyCursor(); + m_isBusy = false; + } +} #endif // getDisplaySize