Skip to content

Commit 4876917

Browse files
drelaptophuangwei1024
authored andcommitted
a workaround to fix black screen on macOS 10.14 (cocos2d#19090)
1 parent a9dbbac commit 4876917

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

cocos/platform/CCGLView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ class CC_DLL GLView : public Ref
433433

434434
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
435435
virtual id getCocoaWindow() = 0;
436+
virtual id getNSGLContext() = 0; // stevetranby: added
436437
#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) */
437438

438439
/**

cocos/platform/desktop/CCGLViewImpl-desktop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class CC_DLL GLViewImpl : public GLView
138138

139139
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
140140
id getCocoaWindow() override { return glfwGetCocoaWindow(_mainWindow); }
141+
id getNSGLContext() override { return glfwGetNSGLContext(_mainWindow); } // stevetranby: added
141142
#endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
142143

143144
protected:

cocos/platform/mac/CCApplication-mac.mm

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,21 @@ static long getCurrentMillSecond()
7979

8080
// Retain glview to avoid glview being released in the while loop
8181
glview->retain();
82-
82+
83+
unsigned int ctx_updated_count = 0;
84+
8385
while (!glview->windowShouldClose())
8486
{
8587
lastTime = getCurrentMillSecond();
86-
88+
89+
// hack to fix issue #19080, black screen on macOS 10.14
90+
// stevetranby: look into doing this outside loop to get rid of condition test per frame
91+
if(ctx_updated_count < 2) {
92+
ctx_updated_count++;
93+
NSOpenGLContext* ctx = (NSOpenGLContext*)glview->getNSGLContext();
94+
[ctx update];
95+
}
96+
8797
director->mainLoop();
8898
glview->pollEvents();
8999

0 commit comments

Comments
 (0)