- fixed potential crash on fatal error in Cocoa backend

Early fatal error can be triggered when native OpenGL frame buffer is not created yet and DDummyFrameBuffer is still used
This commit is contained in:
alexey.lysiuk 2018-06-29 17:14:58 +03:00
parent 8ac864b007
commit 1ebc169d56

View file

@ -319,6 +319,9 @@ NSOpenGLPixelFormat* CreatePixelFormat(const NSOpenGLPixelFormatAttribute profil
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
static SystemGLFrameBuffer* frameBuffer;
SystemGLFrameBuffer::SystemGLFrameBuffer(void*, const bool fullscreen) SystemGLFrameBuffer::SystemGLFrameBuffer(void*, const bool fullscreen)
: DFrameBuffer(vid_defwidth, vid_defheight) : DFrameBuffer(vid_defwidth, vid_defheight)
, m_window(CreateWindow(STYLE_MASK_WINDOWED)) , m_window(CreateWindow(STYLE_MASK_WINDOWED))
@ -383,6 +386,8 @@ SystemGLFrameBuffer::SystemGLFrameBuffer(void*, const bool fullscreen)
} }
} }
frameBuffer = this;
FConsoleWindow::GetInstance().Show(false); FConsoleWindow::GetInstance().Show(false);
} }
@ -532,24 +537,19 @@ void SystemGLFrameBuffer::SetMode(const bool fullscreen, const bool hiDPI)
} }
static SystemGLFrameBuffer* GetSystemFrameBuffer()
{
return static_cast<SystemGLFrameBuffer*>(screen);
}
void SystemGLFrameBuffer::UseHiDPI(const bool hiDPI) void SystemGLFrameBuffer::UseHiDPI(const bool hiDPI)
{ {
if (auto fb = GetSystemFrameBuffer()) if (frameBuffer != nullptr)
{ {
fb->SetMode(fb->m_fullscreen, hiDPI); frameBuffer->SetMode(frameBuffer->m_fullscreen, hiDPI);
} }
} }
void SystemGLFrameBuffer::SetCursor(NSCursor* cursor) void SystemGLFrameBuffer::SetCursor(NSCursor* cursor)
{ {
if (auto fb = GetSystemFrameBuffer()) if (frameBuffer != nullptr)
{ {
NSWindow* const window = fb->m_window; NSWindow* const window = frameBuffer->m_window;
CocoaView* const view = [window contentView]; CocoaView* const view = [window contentView];
[view setCursor:cursor]; [view setCursor:cursor];
@ -559,15 +559,15 @@ void SystemGLFrameBuffer::SetCursor(NSCursor* cursor)
void SystemGLFrameBuffer::SetWindowVisible(bool visible) void SystemGLFrameBuffer::SetWindowVisible(bool visible)
{ {
if (auto fb = GetSystemFrameBuffer()) if (frameBuffer != nullptr)
{ {
if (visible) if (visible)
{ {
[fb->m_window orderFront:nil]; [frameBuffer->m_window orderFront:nil];
} }
else else
{ {
[fb->m_window orderOut:nil]; [frameBuffer->m_window orderOut:nil];
} }
I_SetNativeMouse(!visible); I_SetNativeMouse(!visible);
@ -576,11 +576,11 @@ void SystemGLFrameBuffer::SetWindowVisible(bool visible)
void SystemGLFrameBuffer::SetWindowTitle(const char* title) void SystemGLFrameBuffer::SetWindowTitle(const char* title)
{ {
if (auto fb = GetSystemFrameBuffer()) if (frameBuffer != nullptr)
{ {
NSString* const nsTitle = nullptr == title ? nil : NSString* const nsTitle = nullptr == title ? nil :
[NSString stringWithCString:title encoding:NSISOLatin1StringEncoding]; [NSString stringWithCString:title encoding:NSISOLatin1StringEncoding];
[fb->m_window setTitle:nsTitle]; [frameBuffer->m_window setTitle:nsTitle];
} }
} }