Fixed bug 1239 - Crash in iPad with iOS 3.2 because of missing contentScaleFactor support
authorSam Lantinga
Sat, 07 Jan 2012 01:21:50 -0500
changeset 616467f122d8284f
parent 6163 aa4d1d639f2e
child 6165 b7347e716ab6
Fixed bug 1239 - Crash in iPad with iOS 3.2 because of missing contentScaleFactor support

Joseba GarcĂ­a Echebarria 2011-06-30 19:03:56 PDT
I just found that SDL is crashing in the iPad simulator for iOS 3.2 but not for
iOS 4.2 or over when compiling with Xcode 4.0.2.
The Xcode debugger points to line 127 in video/uikit/SDL_uikitopenglview.m as
the line that triggers the crash.
On those lines one can find:

/* Use the main screen scale (for retina display support) */
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
self.contentScaleFactor = [UIScreen mainScreen].scale;

I believe the problem to be that the "scale" selector is supported in iOS 3.2
in the iPad, but contentScaleFactor is not.
I'm no expert in Objective-C, but I believe the following code to be more
correct (it doesn't crash for me):
/* Use the main screen scale (for retina display support) */
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] &&
[self respondsToSelector:@selector(contentScaleFactor)])
self.contentScaleFactor = [UIScreen mainScreen].scale;

The same check is being performed in line 155 so I imagine it will crash there,
too.

Vittorio Giovara 2011-08-22 17:58:20 PDT

yeah, -scale was introduced in 3.2 but made available only in 4.0, weird
anyways we just need to check against contentScaleFactor as we can be sure that
both are availble starting from 4.0

the attached patch addresses this
src/video/uikit/SDL_uikitopenglview.m
     1.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Sat Jan 07 01:13:15 2012 -0500
     1.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Sat Jan 07 01:21:50 2012 -0500
     1.3 @@ -80,7 +80,7 @@
     1.4  
     1.5          // !!! FIXME: use the screen this is on!
     1.6          /* Use the main screen scale (for retina display support) */
     1.7 -        if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
     1.8 +        if ([self respondsToSelector:@selector(contentScaleFactor)])
     1.9              self.contentScaleFactor = [UIScreen mainScreen].scale;
    1.10  
    1.11          /* create the buffers */