Skip to content

Commit 6857abd

Browse files
committed
macOS: 10.13 should use OpenGL renderer
There appears to be a problem with SDL's Metal renderer under 10.13 (segfault on window creation).
1 parent f03baa0 commit 6857abd

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/macos.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
2626

2727
/* Platform-specific functionality for macOS */
2828

29+
iBool shouldDefaultToMetalRenderer_MacOS (void);
30+
2931
void setupApplication_MacOS (void);
3032
void insertMenuItems_MacOS (const char *menuLabel, int atIndex, const iMenuItem *items, size_t count);
3133
void handleCommand_MacOS (const char *cmd);

src/macos.m

+15-4
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,25 @@
3838
default_TouchBarVariant,
3939
};
4040

41+
static iInt2 macVer_(void) {
42+
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
43+
const NSOperatingSystemVersion ver = [[NSProcessInfo processInfo] operatingSystemVersion];
44+
return init_I2(ver.majorVersion, ver.minorVersion);
45+
}
46+
return init_I2(10, 10);
47+
}
48+
4149
static NSString *currentSystemAppearance_(void) {
4250
/* This API does not exist on 10.13. */
43-
@try {
51+
if ([NSApp respondsToSelector:@selector(effectiveAppearance)]) {
4452
return [[NSApp effectiveAppearance] name];
4553
}
46-
@catch (NSException *) {
47-
return @"NSAppearanceNameAqua";
48-
}
54+
return @"NSAppearanceNameAqua";
55+
}
56+
57+
iBool shouldDefaultToMetalRenderer_MacOS(void) {
58+
const iInt2 ver = macVer_();
59+
return ver.x > 10 || ver.y > 13;
4960
}
5061

5162
/*----------------------------------------------------------------------------------------------*/

src/ui/window.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ void init_Window(iWindow *d, iRect rect) {
522522
d->isDrawFrozen = iTrue;
523523
uint32_t flags = 0;
524524
#if defined (iPlatformApple)
525-
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");
525+
SDL_SetHint(SDL_HINT_RENDER_DRIVER, shouldDefaultToMetalRenderer_MacOS() ? "metal" : "opengl");
526526
#else
527527
flags |= SDL_WINDOW_OPENGL;
528528
#endif

0 commit comments

Comments
 (0)