[TIMOB-4210] iOS - removeEventListener crashes app only on device.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-05-25T17:44:13.000+0000 |
Affected Version/s | Release 1.7.0 |
Fix Version/s | Sprint 2011-21 |
Components | iOS |
Labels | addeventlistener, orientation |
Reporter | Pedro Enrique |
Assignee | Blain Hamon |
Created | 2011-05-24T17:37:20.000+0000 |
Updated | 2011-05-25T17:44:13.000+0000 |
Description
Run this code on the device and the app will crash after adding and then removing the event listener on the orientation - after changing the orientation.
var win1 = Ti.UI.createWindow({
orientationModes:[1,2,3,4]
});
var addCount = 0;
var btnAdd = Ti.UI.createButton({
title: "addEvent",
width: 200,
height: 50,
top: 20
});
var btnRemove = Ti.UI.createButton({
title: "removeEvent",
width: 200,
height: 50,
top: 200
});
var orientationCallback = function(e){
Ti.API.info("*** orientationCallback called ***");
};
btnAdd.addEventListener('click', function(){
Ti.API.info("*** ADDING ORIENTATIONCHANGE EVENT");
Ti.Gesture.addEventListener('orientationchange', orientationCallback);
if(addCount > 0){
Ti.API.info("*** ROTATE NOW");
}
addCount++;
});
btnRemove.addEventListener('click', function(){
Ti.API.info("*** REMOVING ORIENTATIONCHANGE EVENT");
Ti.Gesture.removeEventListener('orientationchange', orientationCallback);
});
win1.add(btnAdd);
win1.add(btnRemove);
win1.open();
And this is from Xcode's console:
[INFO] *** ADDING ORIENTATIONCHANGE EVENT
[INFO] *** orientationCallback called ***
[INFO] *** orientationCallback called ***
[INFO] *** REMOVING ORIENTATIONCHANGE EVENT
[INFO] *** ADDING ORIENTATIONCHANGE EVENT
[INFO] *** ROTATE NOW
[Switching to process 13315 thread 0x0]
[Switching to process 13315 thread 0x0]
Current language: auto; currently c++
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J2)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
(gdb) bt
#0 TiObjectCallAsFunction (ctx=0x4b4cee4, object=0xa, thisObject=0x1, argumentCount=1, arguments=0x4ab6b70, exception=0x4ab6b6c) at /Users/stiv/src/appcelerator/tijscore/TiCore/API/TiObjectRef.cpp:413
#1 0x00036de2 in -[KrollObject triggerEvent:withObject:thisObject:] (self=0x4cefc0, _cmd=0x186560, eventName=0x1bd6dc, eventData=0x4cf5f0, thisObject=0x4cefc0) at /Users/Pedro/Desktop/test/build/iphone/Classes/KrollObject.m:1513
#2 0x0002b29e in -[KrollEvent invoke:] (self=0x4cf650, _cmd=0x185a22, context=0x4abfc0) at /Users/Pedro/Desktop/test/build/iphone/Classes/KrollContext.mm:597
#3 0x0002a9cc in -[KrollContext invoke:] (self=0x4abfc0, _cmd=0x185a22, object=0x4cf650) at /Users/Pedro/Desktop/test/build/iphone/Classes/KrollContext.mm:828
#4 0x0002ccb4 in -[KrollContext main] (self=0x4abfc0, _cmd=0x317445d5) at /Users/Pedro/Desktop/test/build/iphone/Classes/KrollContext.mm:1138
#5 0x34bc9388 in -[NSThread main] ()
#6 0x34c3b5cc in __NSThread__main__ ()
#7 0x3605f310 in _pthread_start ()
#8 0x36060bbc in thread_start ()
Tweaked how we deleted things and learned the importance of TiValueToObject.
Tested with 1.7.0.364c307... on ipod 3g 4.0.2