libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.44k stars 1.75k forks source link

SDL3 SDL_Init crash on ios 15 #10309

Open Zamyk opened 2 months ago

Zamyk commented 2 months ago

I have problem getting my program to run on the ios < 16 (on new versions it works fine), it crashes during SDL_VideoInit. It seems that check at SDL_uikitmodes.m:

https://github.com/libsdl-org/SDL/blob/e949f12f63cdfcef4bdf456936ee676e0a3f9de6/src/video/uikit/SDL_uikitmodes.m#L248-L256

is ignored, with debugger I can step-over into that if (going in to ios >= 16 code even tho its running on ios 15) and then app crashes. I added logging of ios version but its correct.

I found something maybe relevant on stackoverflow: https://stackoverflow.com/questions/73278501/code-behind-availableios-16-0-check-is-called-on-ios-15-causing-crash-on

Workaround: I changed way of checking ios version and it solves the issue:

NSString *reqSysVer = @"16.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending) {    
  if (uiscreen.currentEDRHeadroom > 1.0f) {
    display.HDR.HDR_headroom = uiscreen.currentEDRHeadroom;
  }
  else {
    display.HDR.HDR_headroom = uiscreen.potentialEDRHeadroom;
  }
}

I tried on: simulator iphone se 1 ios 15.2 simulator iphone 7 ios 15.5

slouken commented 2 months ago

Does it work on real devices? Apple is tracking this issue as rdar://132011240

Zamyk commented 2 months ago

Currently I don't have device with ios < 16, but If I get my hands on one I will check it.

natbro commented 1 month ago

we're having trouble reproducing this one with a simple project on SDL2, but totally understand it's happening. Do you happen to have a project you can share here or to natbro@apple.com so we can better reproduce this. If you wouldn't mind adding your macOS version and Xcode version, that would really be a help.

Zamyk commented 1 month ago

@natbro Sorry for taking so long to respond, I was on vacation. I will try to create an example project and send it in the next few days. I'm using macOS Sonoma 14.4.1 and Xcode 15.4. I'm also using CMake to generate the Xcode project. Edit: I've sent it