Problem
When Ti.App.addEventListener() is called from a commonJS unit, other attempts to add an event listener to Ti.App on the same event in normal app units, and then remove that event listener, causes a crash:
{noformat}----- Titanium Javascript Runtime Error -----
E/TiJSError( 667): (main) [1,3676] - In ti:/events.js:241,23
E/TiJSError( 667): (main) [0,3676] - Message: Uncaught TypeError: Cannot read property '0' of undefined
E/TiJSError( 667): (main) [0,3676] - Source: if (list.listener[i] === listener ||
E/V8Exception( 667): Exception occurred at ti:/events.js:241: Uncaught TypeError: Cannot read property '0' of undefined{noformat}
*This is a regression*, as it did not occur in SDK 1.8.1.
Testcase
Ti.App.addEventListener(a,b) is called from a commonJS unit. Another Ti.App.addEventListener(a,c) is called from app.js (notice that the first parameter, the event name, is the same in both calls). Also in app.js, Ti.App.removeEventListener(a,c) is called, which causes the crash.
Put the following code into a new Ti mobile project and run it to the emulator. The crash occurs without any interaction, as soon as the main window appears.
var Procs=require('CommonProcs');
Procs.FirstStep();
var win1=Ti.UI.createWindow({
exitOnClose:true,
navBarHidden:true
})
var TheLabel=Ti.UI.createLabel({
color:'white',
text:'Hello World',
width:'auto'
});
win1.add(TheLabel);
win1.open();
function MainWinOrientationChange()
{
Ti.API.info('MainWinOrientationChange');
}
Ti.App.addEventListener('CustomOrientationChange',MainWinOrientationChange);
Ti.App.removeEventListener('CustomOrientationChange',MainWinOrientationChange);
exports.FirstStep=function()
{
function EmbededHandler()
{
Ti.API.info('test');
}
// Removing the following line or changing the first parameter
// causes the crash to not occur.
Ti.App.addEventListener('CustomOrientationChange',EmbededHandler);
};
I can confirm this issue for component-based events. I didn't try to isolate the issue, but I not using app-level events and I'm getting this error message when I compile app with 1.8.2 (1.8.1 don't have this issue).
I confirm that I have the same issue with SDK 1.8.2 : when a window (with an event listener associated to it) is closed I have the same Javascript Runtime Error. The event listeners manager may not be able to find and delete the event listener associated to the window closed... I also confirm that the bug is not present in SDK 1.8.1.
Has this fix been merged into the 1_8_X branch?
Closing as Fixed. Tested with Ping's code. Expected Behavior: Removing event listeners will not cause the associated runtime error. SDK: 2.0.0.v20120316130302 Android: V8, Rhino Studio: 2.0.0.201203152033 OS: Snow Leopard Devices Tested: Nexus One 2.2.2 Note: This bug does not involve CommonJS Modules.
Verified fix on SDK 2.0.0.v20120319003254. Thanks!