We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1239

Summary: Crash in iPad with iOS 3.2 because of missing contentScaleFactor support
Product: SDL Reporter: Joseba García Echebarria <joseba.gar>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: critical    
Priority: P2    
Version: HG 2.0   
Hardware: iPhone/iPod touch   
OS: iOS 3   
Bug Depends on:    
Bug Blocks: 1266    
Attachments: fix
updated fix for -contentScaleFactor check

Description Joseba García Echebarria 2011-06-30 19:03:56 UTC
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.
Comment 1 Vittorio Giovara 2011-08-22 17:58:20 UTC
Created attachment 681 [details]
fix

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
Comment 2 Vittorio Giovara 2011-11-20 09:24:12 UTC
Created attachment 729 [details]
updated fix for -contentScaleFactor check

I've attached an updated version of the patch.
Comment 3 Sam Lantinga 2012-01-06 22:22:10 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL/rev/67f122d8284f