Skip to content

Commit 08a6562

Browse files
committed
OSX/MACOS: Fix unreachable NSOpenGLPixelFormat fallback guard
cocoa_gl_ctx.m had a fallback path that retried pixel-format creation without NSOpenGLPFAAllowOfflineRenderers when the first -initWithAttributes: returned nil, guarded by #if MAC_OS_X_VERSION_MIN_REQUIRED < 1050 MIN_REQUIRED is the deployment target; < 1050 means "the binary is allowed to run on pre-10.5". NSOpenGLPFAAllowOfflineRenderers was added in 10.5, so the intent was clearly "compile the fallback when the SDK or deployment target might not support this flag". The guard as written is inverted - it only fires when targeting pre-10.5, not when targeting 10.5+ - so on every shipping build the fallback was simply dead code. The guard is also unreachable in practice regardless: the static `attributes` initializer a few lines above references NSOpenGLPFAAllowOfflineRenderers unconditionally, which means the file already demands MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 at the SDK level just to compile. A pre-10.5 target that somehow got through would have failed on the attribute reference long before reaching this code. Just remove the guard. The fallback is now always compiled and only exercised at runtime when the first pixel-format creation returns nil - which can still happen on early 10.5 builds where some drivers rejected the offline-renderers flag despite the constant being exposed, or more generally on any platform where pixel-format creation fails for any reason. Previously those cases produced a silently broken state (nil g_ctx, no visible error) because the function returns true regardless. The retry-without-flag path gives us one more chance to recover.
1 parent bd45086 commit 08a6562

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

gfx/drivers_context/cocoa_gl_ctx.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,22 @@ static bool cocoa_gl_gfx_ctx_set_video_mode(void *data,
429429

430430
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
431431

432-
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
432+
/* If pixel-format creation failed with NSOpenGLPFAAllowOfflineRenderers
433+
* (added in 10.5 - some drivers on early 10.5 builds could reject it
434+
* even though the SDK exposed the constant), retry without it. The
435+
* previous guard here was #if MAC_OS_X_VERSION_MIN_REQUIRED < 1050,
436+
* which meant "compile this fallback only when targeting pre-10.5" -
437+
* the opposite of what was intended and unreachable in practice since
438+
* the static `attributes` array above already references
439+
* NSOpenGLPFAAllowOfflineRenderers unconditionally, so the file
440+
* demands a 10.5+ SDK (MAC_OS_X_VERSION_MAX_ALLOWED >= 1050) just
441+
* to compile. The fallback is now always available at runtime and
442+
* only exercised when the first -initWithAttributes: returns nil. */
433443
if (fmt == nil)
434444
{
435-
/* NSOpenGLFPAAllowOfflineRenderers is
436-
not supported on this OS version. */
437445
attributes[3] = (NSOpenGLPixelFormatAttribute)0;
438446
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
439447
}
440-
#endif
441448

442449
if (cocoa_ctx->flags & COCOA_CTX_FLAG_USE_HW_CTX)
443450
{

0 commit comments

Comments
 (0)