Skip to content

Commit 3f503f5

Browse files
committed
More work on python lifecycle
1 parent c89b0cc commit 3f503f5

22 files changed

+382
-109
lines changed

modules/yup_core/logging/yup_Logger.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ void YUP_API YUP_CALLTYPE logAssertion (const char* const filename, const int li
6969
String m ("YUP Assertion failure in ");
7070
m << File::createFileWithoutCheckingPath (CharPointer_UTF8 (filename)).getFileName() << ':' << lineNum;
7171

72+
#if YUP_ASSERT_INCLUDE_STACKTRACE
73+
m << newLine << SystemStats::getStackBacktrace();
74+
#endif
75+
7276
#if YUP_LOG_ASSERTIONS
7377
Logger::writeToLog (m);
7478
#else
@@ -81,6 +85,10 @@ void YUP_API YUP_CALLTYPE logAssertion (const wchar_t* const filename, const int
8185
String m ("YUP Assertion failure in ");
8286
m << File::createFileWithoutCheckingPath (filename).getFileName() << ':' << lineNum;
8387

88+
#if YUP_ASSERT_INCLUDE_STACKTRACE
89+
m << newLine << SystemStats::getStackBacktrace();
90+
#endif
91+
8492
#if YUP_LOG_ASSERTIONS
8593
Logger::writeToLog (m);
8694
#else

modules/yup_core/yup_core.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@
105105
#endif
106106
#endif
107107

108+
//==============================================================================
109+
/** Config: YUP_ASSERT_INCLUDE_STACKTRACE
110+
111+
If this flag is enabled, the jassert and jassertfalse macros will include
112+
a stack trace when an assertion happens.
113+
114+
@see YUP_LOG_ASSERTIONS, jassert, jassertfalse
115+
*/
116+
#ifndef YUP_ASSERT_INCLUDE_STACKTRACE
117+
#define YUP_ASSERT_INCLUDE_STACKTRACE 1
118+
#endif
119+
108120
//==============================================================================
109121
/** Config: YUP_CHECK_MEMORY_LEAKS
110122

modules/yup_events/messages/yup_DeletedAtShutdown.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
namespace yup
4141
{
4242

43-
static SpinLock deletedAtShutdownLock; // use a spin lock because it can be statically initialised
43+
static SpinLock& getDeletedAtShutdownSpinLock()
44+
{
45+
static SpinLock deletedAtShutdownLock;
46+
return deletedAtShutdownLock;
47+
}
4448

4549
static Array<DeletedAtShutdown*>& getDeletedAtShutdownObjects()
4650
{
@@ -50,13 +54,13 @@ static Array<DeletedAtShutdown*>& getDeletedAtShutdownObjects()
5054

5155
DeletedAtShutdown::DeletedAtShutdown()
5256
{
53-
const SpinLock::ScopedLockType sl (deletedAtShutdownLock);
57+
const SpinLock::ScopedLockType sl (getDeletedAtShutdownSpinLock());
5458
getDeletedAtShutdownObjects().add (this);
5559
}
5660

5761
DeletedAtShutdown::~DeletedAtShutdown()
5862
{
59-
const SpinLock::ScopedLockType sl (deletedAtShutdownLock);
63+
const SpinLock::ScopedLockType sl (getDeletedAtShutdownSpinLock());
6064
getDeletedAtShutdownObjects().removeFirstMatchingValue (this);
6165
}
6266

@@ -71,7 +75,7 @@ void DeletedAtShutdown::deleteAll()
7175
Array<DeletedAtShutdown*> localCopy;
7276

7377
{
74-
const SpinLock::ScopedLockType sl (deletedAtShutdownLock);
78+
const SpinLock::ScopedLockType sl (getDeletedAtShutdownSpinLock());
7579
localCopy = getDeletedAtShutdownObjects();
7680
}
7781

@@ -83,7 +87,7 @@ void DeletedAtShutdown::deleteAll()
8387

8488
// double-check that it's not already been deleted during another object's destructor.
8589
{
86-
const SpinLock::ScopedLockType sl (deletedAtShutdownLock);
90+
const SpinLock::ScopedLockType sl (getDeletedAtShutdownSpinLock());
8791

8892
if (! getDeletedAtShutdownObjects().contains (deletee))
8993
deletee = nullptr;

modules/yup_events/native/yup_MessageManager_ios.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ void runNSApplication()
7070
if (!SystemStats::isRunningInAppExtensionSandbox())
7171
[[[UIApplication sharedApplication] delegate] applicationWillTerminate:[UIApplication sharedApplication]];
7272

73+
#if YUP_SHUTDOWN_APP_ON_MESSAGEMANAGER_QUIT
7374
exit(0); // iOS apps get no mercy..
75+
#endif
7476
}
7577

7678
#if YUP_MODAL_LOOPS_PERMITTED

modules/yup_events/native/yup_MessageManager_mac.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static bool runNSApplication(int millisecondsToRunFor, Atomic<int>& quitMessageP
387387
@try
388388
{
389389
#endif
390-
CFRunLoopRunInMode(kCFRunLoopCommonModes, jmin(1.0, msRemaining * 0.001), true);
390+
CFRunLoopRunInMode(kCFRunLoopDefaultMode, jmin(1.0, msRemaining * 0.001), true);
391391

392392
#if YUP_CATCH_UNHANDLED_EXCEPTIONS
393393
}
@@ -444,7 +444,9 @@ static void shutdownNSApp()
444444
for (const auto& func : shutdownCallbacks)
445445
func();
446446

447+
#if YUP_SHUTDOWN_APP_ON_MESSAGEMANAGER_QUIT
447448
shutdownNSApp();
449+
#endif
448450
}
449451
else
450452
{

modules/yup_events/timers/yup_Timer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
namespace yup
4141
{
4242

43-
class Timer::TimerThread final : private Thread
44-
, private DeletedAtShutdown
43+
class Timer::TimerThread final : private Thread, private DeletedAtShutdown
4544
{
4645
static inline constexpr int maxTimeoutMilliseconds = 10;
4746

modules/yup_events/timers/yup_Timer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ class YUP_API Timer
137137
static void YUP_CALLTYPE callAfterDelay (int milliseconds, std::function<void()> functionToCall);
138138

139139
//==============================================================================
140-
/** For internal use only: invokes any timers that need callbacks.
141-
Don't call this unless you really know what you're doing!
142-
*/
140+
/** @internal Invokes any timers that need callbacks. Don't call this unless you really know what you're doing! */
143141
static void YUP_CALLTYPE callPendingTimersSynchronously();
144142

145143
private:

modules/yup_events/yup_events.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@
7171
#define YUP_EXECUTE_APP_SUSPEND_ON_BACKGROUND_TASK 0
7272
#endif
7373

74+
//==============================================================================
75+
/** Config: YUP_SHUTDOWN_APP_ON_MESSAGEMANAGER_QUIT
76+
77+
Will shutdown the application when the MessageManager is quit.
78+
*/
79+
#ifndef YUP_SHUTDOWN_APP_ON_MESSAGEMANAGER_QUIT
80+
#define YUP_SHUTDOWN_APP_ON_MESSAGEMANAGER_QUIT 1
81+
#endif
82+
7483
#if YUP_WINDOWS && YUP_EVENTS_INCLUDE_WINRT_WRAPPER
7584
// If this header file is missing then you are probably attempting to use WinRT
7685
// functionality without the WinRT libraries installed on your system. Try installing

modules/yup_graphics/graphics/yup_Color.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,28 @@ class YUP_API Color
792792
};
793793
}
794794

795+
//==============================================================================
796+
797+
static Color fromRGB (uint8 r, uint8 g, uint8 b) noexcept
798+
{
799+
return { 255, r, g, b };
800+
}
801+
802+
static Color fromRGBA (uint8 r, uint8 g, uint8 b, uint8 a) noexcept
803+
{
804+
return { a, r, g, b };
805+
}
806+
807+
static Color fromARGB (uint8 a, uint8 r, uint8 g, uint8 b) noexcept
808+
{
809+
return { a, r, g, b };
810+
}
811+
812+
static Color fromBGRA (uint8 b, uint8 g, uint8 r, uint8 a) noexcept
813+
{
814+
return { a, r, g, b };
815+
}
816+
795817
//==============================================================================
796818
// TODO - doxygen
797819
String toString() const;

modules/yup_gui/native/yup_Windowing_sdl2.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,8 @@ void shutdownYup_Windowing()
16491649

16501650
// Shutdown desktop
16511651
SDL_DelEventWatch (displayEventDispatcher, Desktop::getInstance());
1652-
Desktop::getInstance()->deleteInstance();
1652+
if (auto desktop = Desktop::getInstanceWithoutCreating())
1653+
desktop->deleteInstance();
16531654

16541655
// Unregister theme
16551656
{
@@ -1658,7 +1659,8 @@ void shutdownYup_Windowing()
16581659
}
16591660

16601661
// Unregister event loop
1661-
MessageManager::getInstance()->registerEventLoopCallback (nullptr);
1662+
if (auto messageManager = MessageManager::getInstanceWithoutCreating())
1663+
messageManager->registerEventLoopCallback (nullptr);
16621664

16631665
// Quit SDL
16641666
SDL_Quit();

0 commit comments

Comments
 (0)