|
66 | 66 |
|
67 | 67 | namespace os {
|
68 | 68 |
|
| 69 | +// Extern raw reference to current system instance. |
| 70 | +extern System* g_instance; |
| 71 | + |
69 | 72 | // Converts an os::Hit to a Win32 hit test value
|
70 | 73 | static int hit2hittest[] = {
|
71 | 74 | HTNOWHERE, // os::Hit::None
|
@@ -135,7 +138,7 @@ static BOOL CALLBACK log_monitor_info(HMONITOR monitor,
|
135 | 138 |
|
136 | 139 | std::wstring get_wnd_class_name()
|
137 | 140 | {
|
138 |
| - if (auto sys = instance()) { |
| 141 | + if (auto sys = os::System::instance()) { |
139 | 142 | if (!sys->appName().empty())
|
140 | 143 | return base::from_utf8(sys->appName());
|
141 | 144 | }
|
@@ -322,12 +325,17 @@ WindowWin::WindowWin(const WindowSpec& spec)
|
322 | 325 |
|
323 | 326 | WindowWin::~WindowWin()
|
324 | 327 | {
|
325 |
| - auto sys = system(); |
| 328 | + // We cannot use os::System::instance() here because that would add |
| 329 | + // a new reference to a possible dying System pointer, e.g. when we |
| 330 | + // come from ~System because the last Ref::unref() was called and |
| 331 | + // this window is being destroyed because its last reference was in |
| 332 | + // a os::Event of the os::EventQueue. |
| 333 | + SystemWin* sys = (SystemWin*)g_instance; |
326 | 334 |
|
327 | 335 | // If this assert fails it's highly probable that an os::WindowRef
|
328 | 336 | // was kept alive in some kind of memory leak (or just inside an
|
329 | 337 | // os::Event in the os::EventQueue). Also this can happen when
|
330 |
| - // declaring a os::WindowRef before calling os::make_system(), |
| 338 | + // declaring a os::WindowRef before calling os::System::system(), |
331 | 339 | // because of deletion order when destructors got called.
|
332 | 340 | ASSERT(sys);
|
333 | 341 |
|
|
0 commit comments