Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3160] iOS: removeEventListener crashes when passed 'this'

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2011-11-05T15:46:33.000+0000
Affected Version/sRelease 1.5.1
Fix Version/sSprint 2011-22, Release 1.8.0
ComponentsiOS
Labelsn/a
ReporterJon Alter
AssigneeReggie Seagraves
Created2011-04-15T03:38:21.000+0000
Updated2011-11-05T15:46:33.000+0000

Description

Application crashes when you try to use 'this' in removeEventListener to remove an addEventListener who's function you are in.

This code sample if from the code example at http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Animation-object"> http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI....


var view = Titanium.UI.createView({
   backgroundColor:'red'
});
var animation = Titanium.UI.createAnimation();
animation.backgroundColor = 'black';
animation.duration = 1000;
animation.addEventListener('complete',function()
{
   animation.removeEventListener('complete',this);
   animation.backgroundColor = 'orange';
   view.animate(animation);
});
view.animate(animation);

tested with 1.5.1, 1.6.0RC1, iOS SDK 4.2

Associated Helpdesk Ticket

http://developer.appcelerator.com/helpdesk/view/73881">http://developer.appcelerator.com/helpdesk/view/73881

Comments

  1. marky 2011-04-15

    You might use 'arguments.callee' instead of 'this' to solve this issue.

    'arguments.callee' is itself that no name inner function.

    animation.addEventListener('complete',function()
    { animation.backgroundColor = 'orange'; view.animate(animation); animation.removeEventListener('complete', arguments.callee); });

    sorry, poor my english.

  2. Reggie Seagraves 2011-06-03

    This is actually failing properly. The sample code in the API doc has been updated to show the proper way to do this.
  3. Jon Alter 2011-06-03

    this is pointing to the animation not the function.
  4. Eric Merriman 2011-06-06

    Waiting for 1.7.0 to push which should update API docs.
  5. Alan Vaghti 2011-09-22

    While testing fix, corresponding Android bug was opened: TIMOB-5340
  6. Alan Vaghti 2011-10-06

    Fix verified in 1.8.0.v20111006001414. The application no longer crashes, but it also never transitions to orange. A new bug was filed for that issue: TIMOB-5459
  7. Don Thorp 2011-11-05

    Standardizing summary and labels.

JSON Source