Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23118] iOS: Ti.UI.iOS.DynamicItemBehavior can possibly crash during iteration

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2016-04-07T23:36:43.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.4.0
ComponentsiOS
Labelsdynamicitembehavior, qe-5.4.0
ReporterHans Knöchel
AssigneeHans Knöchel
Created2016-03-28T19:24:34.000+0000
Updated2016-08-09T21:29:48.000+0000

Description

A community member created a PR to fix a crash that can occur with the above mentioned API. The fix removes the fast-enumeration with a simple for-iteration.

Comments

  1. Hans Knöchel 2016-03-28

    PR: https://github.com/appcelerator/titanium_mobile/pull/6600 Demo:
       var win = Ti.UI.createWindow({backgroundColor: 'white', fullscreen: true});
       
       // Create an Animator object using the window as the coordinate system
       var animator = Ti.UI.iOS.createAnimator({referenceView: win});
       
       // Create a red block
       var redBlock = Ti.UI.createView({
           backgroundColor: 'red',
           width: 25,
           height: 25,
           top: 25,
           left: 25
       });
       
       // Change the physics attributes of the red block
       var redDynamic = Ti.UI.iOS.createDynamicItemBehavior({
           density: 20.0,
           angularResistance: 1.0,
           friction: 1.0,
           resistance: 1.0,
           allowsRotation: false
       });
       redDynamic.addItem(redBlock);
       
       // Apply a left push to the red block
       var redPush = Ti.UI.iOS.createPushBehavior({
           pushDirection: {x: 2.0, y: 0.0}
       });
       redPush.addItem(redBlock);
       
       // Create a blue block
       var blueBlock = Ti.UI.createView({
           backgroundColor: 'blue',
           width: 50,
           height: 50,
           top: 25,
           right: 25
       });
       
       // Change the physics attributes of the blue block
       var blueDynamic = Ti.UI.iOS.createDynamicItemBehavior({
           elasticity: 1.0,
       });
       blueDynamic.addItem(blueBlock);
       
       // Apply a right push to the blue block
       var bluePush = Ti.UI.iOS.createPushBehavior({
           pushDirection: {x: -2.0, y: 0.0}
       });
       bluePush.addItem(blueBlock);
       
       // Create the collision behavior so the items can collide
       var collision = Ti.UI.iOS.createCollisionBehavior();
       collision.addItem(redBlock);
       collision.addItem(blueBlock);
       
       animator.addBehavior(redDynamic);
       animator.addBehavior(redPush);
       animator.addBehavior(blueDynamic);
       animator.addBehavior(bluePush);
       animator.addBehavior(collision);
       
       // Start the animation when the window opens
       win.addEventListener('open', function(e){
           animator.startAnimator();
       });
       
       win.add(redBlock);
       win.add(blueBlock);
       win.open();
       
  2. Harry Bryant 2016-08-09

    Verified as fixed, ran the app with the above demo code 10 times without a single crash. Tested On: iPhone 6S (9.3.3) Device Mac OSX El Capitan 10.11.6 Ti SDK: 5.4.0.v20160809033140 Appc Studio: 4.7.0.201607250649 Appc NPM: 4.2.7 App CLI: 5.4.0-40 Xcode 7.3.1 Node v4.4.7 *Closing ticket.*

JSON Source