• Sam Lantinga's avatar
    Fixed bug 1239 - Crash in iPad with iOS 3.2 because of missing contentScaleFactor support · de93e295
    Sam Lantinga authored
    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
    de93e295
Name
Last commit
Last update
..
atomic Loading commit data...
audio Loading commit data...
core Loading commit data...
cpuinfo Loading commit data...
events Loading commit data...
file Loading commit data...
haptic Loading commit data...
joystick Loading commit data...
libm Loading commit data...
loadso Loading commit data...
main Loading commit data...
power Loading commit data...
render Loading commit data...
stdlib Loading commit data...
thread Loading commit data...
timer Loading commit data...
video Loading commit data...
SDL.c Loading commit data...
SDL_assert.c Loading commit data...
SDL_assert_c.h Loading commit data...
SDL_compat.c Loading commit data...
SDL_error.c Loading commit data...
SDL_error_c.h Loading commit data...
SDL_fatal.c Loading commit data...
SDL_fatal.h Loading commit data...
SDL_hints.c Loading commit data...
SDL_hints_c.h Loading commit data...
SDL_log.c Loading commit data...