Skip to content

Commit

Permalink
macOS: 10.13 should use OpenGL renderer
Browse files Browse the repository at this point in the history
There appears to be a problem with SDL's Metal renderer under 10.13 (segfault on window creation).
  • Loading branch information
skyjake committed Sep 27, 2020
1 parent f03baa0 commit 6857abd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/macos.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

/* Platform-specific functionality for macOS */

iBool shouldDefaultToMetalRenderer_MacOS (void);

void setupApplication_MacOS (void);
void insertMenuItems_MacOS (const char *menuLabel, int atIndex, const iMenuItem *items, size_t count);
void handleCommand_MacOS (const char *cmd);
19 changes: 15 additions & 4 deletions src/macos.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,25 @@
default_TouchBarVariant,
};

static iInt2 macVer_(void) {
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
const NSOperatingSystemVersion ver = [[NSProcessInfo processInfo] operatingSystemVersion];
return init_I2(ver.majorVersion, ver.minorVersion);
}
return init_I2(10, 10);
}

static NSString *currentSystemAppearance_(void) {
/* This API does not exist on 10.13. */
@try {
if ([NSApp respondsToSelector:@selector(effectiveAppearance)]) {
return [[NSApp effectiveAppearance] name];
}
@catch (NSException *) {
return @"NSAppearanceNameAqua";
}
return @"NSAppearanceNameAqua";
}

iBool shouldDefaultToMetalRenderer_MacOS(void) {
const iInt2 ver = macVer_();
return ver.x > 10 || ver.y > 13;
}

/*----------------------------------------------------------------------------------------------*/
Expand Down
2 changes: 1 addition & 1 deletion src/ui/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void init_Window(iWindow *d, iRect rect) {
d->isDrawFrozen = iTrue;
uint32_t flags = 0;
#if defined (iPlatformApple)
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");
SDL_SetHint(SDL_HINT_RENDER_DRIVER, shouldDefaultToMetalRenderer_MacOS() ? "metal" : "opengl");
#else
flags |= SDL_WINDOW_OPENGL;
#endif
Expand Down

0 comments on commit 6857abd

Please sign in to comment.