Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4201] iOS: Ti.Platform.displayCaps is undefined if called from another context

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2011-06-20T09:59:37.000+0000
Affected Version/sRelease 1.7.0
Fix Version/sSprint 2011-24
ComponentsiOS
Labelsregression
ReporterJon Alter
AssigneeBlain Hamon
Created2011-05-24T11:27:14.000+0000
Updated2017-03-02T21:06:50.000+0000

Description

If you call Ti.Platform.displayCaps from a different context it says that it is undefined. Step 1: run the code below Step 2: notice the error when you click the button Step 3: when you call the same function from the same context it works fine. app.js
var app ={
	getWidth : function(){
		return Ti.Platform.displayCaps.platformWidth;
	}
};

var win = Ti.UI.createWindow({  
    backgroundColor:'white',
	fullscreen: true
});

var button = Ti.UI.createButton({
	title: 'Width',
	top: 100,
	height: 40,
	width: 200
});
button.addEventListener('click', function(e){
	// alert( app.getWidth() );
	var newWin = Ti.UI.createWindow({  
	    backgroundColor:'blue',
		url: 'win1.js'
	});
	newWin.app = app;
	newWin.open();
});

win.add(button);
win.open();
win1.js
(function(){
	var win = Ti.UI.currentWindow;
	alert( win.app.getWidth() );
})();

Attachments

FileDateSize
4201.crash2011-06-06T14:54:11.000+000020774
Screen shot 2011-05-24 at 11.12.44 AM.png2011-05-24T11:27:14.000+000037977

Comments

  1. Jon Alter 2011-05-25

    Associated Helpdesk Ticket

    http://appc.me/c/APP-783212
  2. Dawson Toth 2011-05-25

    Second Associated Helpdesk Ticket

    http://appc.me/c/APP-367438
  3. Dawson Toth 2011-05-25

    Where The Regression Happened

    I just tested this on a build I made last night from the latest source, and it is working again. So sometime between 1.6.2 and 1.7.0.RC1 this regressed, and from 1.7.0.RC1 to now it was fixed.

    Works With

    Titanium SDK version: 1.8.0 (05/24/11 16:32 ce16436) (pulled from GitHub, built myself)

    Tested With

       Ti.App.Dawson = {
           createRedBox: function() {
               var v = Ti.UI.createView({ backgroundColor: 'red', width: 50, height: 50 });
               v.add(Ti.UI.createLabel({ text: 'Hello!' })); //This line fails with an exception saying v is undefined.
               alert(Ti.Platform.displayCaps.platformWidth);
               return v;
           }
       };
       Ti.UI.createWindow({ url: 'sub.js', backgroundColor: 'white' }).open();
       
       Ti.UI.currentWindow.add(Ti.App.Dawson.createRedBox());
       
  4. Blain Hamon 2011-06-03

    If it's working now, let's call it fixed.
  5. Eric Merriman 2011-06-06

    Now it crashes. Mon Jun 6 14:41:35 unknown ReportCrash[4648] : Formulating crash report for process timob4201[4647] Mon Jun 6 14:41:35 unknown ReportCrash[4648] : Saved crashreport to /var/mobile/Library/Logs/CrashReporter/timob4201_2011-06-06-144135_Pippen.plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0 Mon Jun 6 14:41:35 unknown com.apple.launchd[1] : (UIKitApplication:com.appcelerator.4201[0xea7b]) Job appears to have crashed: Trace/BPT trap Mon Jun 6 14:41:35 unknown SpringBoard[28] : Application 'timob4201' exited abnormally with signal 5: Trace/BPT trap See attached crash log.
  6. Blain Hamon 2011-06-13

    Tempted to mark this is invalid; For reasons of safety, creating proxies in the wrong context is disallowed (It leads to deadlocks or crashes) and so displayCaps, since it wasn't defined previously and would be in the wrong context, is not registered. If you absolutely must make cross-context calls, refer to Ti.Platform.displayCaps in the JS file beforehand.
  7. Blain Hamon 2011-06-20

    No objections to marking this invalid. Creating a proxy cross-context (That includes accessing previously un-accessed globals) was intentionally disallowed to stop things from crashing.
  8. Lee Morris 2017-03-02

    Closed as invalid.

JSON Source