Skip to content

Commit 3c4a88f

Browse files
committed
Use heap allocation for WindowMessageDispatcher singleton
Changed WindowMessageDispatcher::GetInstance to allocate the singleton instance on the heap. This avoids issues with static destruction order and ensures the instance remains valid throughout the program lifetime, including during static destruction.
1 parent a8a2ecb commit 3c4a88f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/platform/windows/window_message_dispatcher.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
namespace nativeapi {
66

77
WindowMessageDispatcher& WindowMessageDispatcher::GetInstance() {
8-
static WindowMessageDispatcher instance;
9-
return instance;
8+
// Use heap allocation to avoid static destruction order issues
9+
// The instance is never destroyed to ensure it remains valid during
10+
// the entire program lifetime, including during static destruction
11+
static auto* instance = new WindowMessageDispatcher();
12+
return *instance;
1013
}
1114

1215
WindowMessageDispatcher::~WindowMessageDispatcher() {

0 commit comments

Comments
 (0)