mirror of
https://github.com/shadps4-emu/ext-SDL.git
synced 2024-12-27 13:16:03 +00:00
cocoa: OpenGL setView and update must be used on main thread (thanks, Tim!).
If called from background threads, use Grand Central Dispatch to use the main thread instead. On the main thread, just call them directly. Fixes Bugzilla #4932.
This commit is contained in:
parent
486f0b6c60
commit
309d6137ae
@ -49,6 +49,8 @@ struct SDL_GLDriverData
|
|||||||
- (void)scheduleUpdate;
|
- (void)scheduleUpdate;
|
||||||
- (void)updateIfNeeded;
|
- (void)updateIfNeeded;
|
||||||
- (void)setWindow:(SDL_Window *)window;
|
- (void)setWindow:(SDL_Window *)window;
|
||||||
|
- (SDL_Window*)window;
|
||||||
|
- (void)explicitUpdate;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -63,14 +63,10 @@
|
|||||||
/* This should only be called on the thread on which a user is using the context. */
|
/* This should only be called on the thread on which a user is using the context. */
|
||||||
- (void)updateIfNeeded
|
- (void)updateIfNeeded
|
||||||
{
|
{
|
||||||
int value = SDL_AtomicSet(&self->dirty, 0);
|
const int value = SDL_AtomicSet(&self->dirty, 0);
|
||||||
if (value > 0) {
|
if (value > 0) {
|
||||||
/* We call the real underlying update here, since -[SDLOpenGLContext update] just calls us. */
|
/* We call the real underlying update here, since -[SDLOpenGLContext update] just calls us. */
|
||||||
if ([NSThread isMainThread]) {
|
[self explicitUpdate];
|
||||||
[super update];
|
|
||||||
} else {
|
|
||||||
[super performSelectorOnMainThread:@selector(update) withObject:nil waitUntilDone:NO];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,9 +115,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ([self view] != contentview) {
|
if ([self view] != contentview) {
|
||||||
[self setView:contentview];
|
if ([NSThread isMainThread]) {
|
||||||
|
[self setView:contentview];
|
||||||
|
} else {
|
||||||
|
dispatch_sync(dispatch_get_main_queue(), ^{ [self setView:contentview]; });
|
||||||
|
}
|
||||||
if (self == [NSOpenGLContext currentContext]) {
|
if (self == [NSOpenGLContext currentContext]) {
|
||||||
[self update];
|
[self explicitUpdate];
|
||||||
} else {
|
} else {
|
||||||
[self scheduleUpdate];
|
[self scheduleUpdate];
|
||||||
}
|
}
|
||||||
@ -129,13 +129,27 @@
|
|||||||
} else {
|
} else {
|
||||||
[self clearDrawable];
|
[self clearDrawable];
|
||||||
if (self == [NSOpenGLContext currentContext]) {
|
if (self == [NSOpenGLContext currentContext]) {
|
||||||
[self update];
|
[self explicitUpdate];
|
||||||
} else {
|
} else {
|
||||||
[self scheduleUpdate];
|
[self scheduleUpdate];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (SDL_Window*)window
|
||||||
|
{
|
||||||
|
return self->window;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)explicitUpdate
|
||||||
|
{
|
||||||
|
if ([NSThread isMainThread]) {
|
||||||
|
[super update];
|
||||||
|
} else {
|
||||||
|
dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@ -352,8 +366,10 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
|||||||
{
|
{
|
||||||
if (context) {
|
if (context) {
|
||||||
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
|
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
|
||||||
[nscontext setWindow:window];
|
if ([nscontext window] != window) {
|
||||||
[nscontext updateIfNeeded];
|
[nscontext setWindow:window];
|
||||||
|
[nscontext updateIfNeeded];
|
||||||
|
}
|
||||||
[nscontext makeCurrentContext];
|
[nscontext makeCurrentContext];
|
||||||
} else {
|
} else {
|
||||||
[NSOpenGLContext clearCurrentContext];
|
[NSOpenGLContext clearCurrentContext];
|
||||||
|
Loading…
Reference in New Issue
Block a user