Skip to content

Fix Catalina by moving some calls to the UI thread. #1959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ A new header is inserted each time a *tag* is created.

## Next release

- Fix bad instruction exception with macOS Catalina.
- Added support for solid and thin layer cubemap and screen-space refraction.
- Improved high roughness material rendering by default when regenerating environments maps.
- Fixed bad state after removing an IBL from the Scene.
Expand Down
24 changes: 10 additions & 14 deletions filament/backend/src/opengl/PlatformCocoaGL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,17 @@
NSView *nsView = (__bridge NSView*) drawSwapChain;
if (pImpl->mCurrentView != nsView) {
pImpl->mCurrentView = nsView;
// Calling setView could change the viewport and/or scissor box state, but this isn't
// accounted for in our OpenGL driver- so we save their state and recall it afterwards.
GLint viewport[4];
GLint scissor[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glGetIntegerv(GL_SCISSOR_BOX, scissor);

[pImpl->mGLContext setView:nsView];

// Recall viewport and scissor state.
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);

// NOTE: This is not documented well (if at all) but Apple requires the following two
// context methods to be called from the UI thread. This became a hard requirement with the
// arrival of macOS 10.15 (Catalina). If we were to call these methods from the GL thread,
// we would see EXC_BAD_INSTRUCTION.
NSOpenGLContext* glContext = pImpl->mGLContext;
dispatch_sync(dispatch_get_main_queue(), ^(void) {
[glContext setView:nsView];
[glContext update];
});
}
// this is needed only when the view resized. Not sure how to do only when needed.
[pImpl->mGLContext update];
}

void PlatformCocoaGL::commit(Platform::SwapChain* swapChain) noexcept {
Expand Down