Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7416] Android: Simple animation causes application crash

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-02-14T23:29:00.000+0000
Affected Version/sRelease 1.8.0.1, Release 2.0.0, Release 1.8.1
Fix Version/sSprint 2012-03, Release 2.0.0, Release 1.8.2
ComponentsAndroid
Labelsparity
ReporterArthur Evans
AssigneePing Wang
Created2012-01-25T23:16:00.000+0000
Updated2013-11-27T12:17:08.000+0000

Description

When running the following code, the animation occurs correctly the first time I click on the view--the green box spins around once, then stops. (If run in a lightweight window, at the finish of the animation, there's a visual anomaly where part of the underlying window shows through. But this is not the bug in question.) The second time I click on the view, the app crashes immediately. Stack trace included below code.

var win1 = Ti.UI.createWindow({
	backgroundColor : "white"
});
var view = Ti.UI.createView({
	height : 100,
	width : 100,
	backgroundColor : "green"
});
win1.add(view);
win1.open();

var matrix = Ti.UI.create2DMatrix();
var matrix1 = matrix.rotate(120);
var matrix2 = matrix.rotate(240);
var transforms = [matrix, matrix1, matrix2];
// We start at 0, so the first rotation is to 120 degrees
var nextTransform = 1;
animation = Ti.UI.createAnimation({
	transform : transforms[nextTransform],
	duration : 500,
});
// On iOS, override the default easing to avoid 
// jerky transitions between animations.
if (Ti.Platform.name === 'iPhone OS') {
	animation.curve = Ti.UI.iOS.ANIMATION_CURVE_LINEAR;
}

animation.addEventListener('complete', function(e) {
	// view.transform = transforms[nextTransform];
	if(nextTransform == 0) {
		// Rotation complete, reset for next time
		nextTransform = 1;
		animation.transform = transforms[nextTransform];
	} else {
		// Rotate to the next position
		nextTransform = (nextTransform + 1) % 3;
		animation.transform = transforms[nextTransform];
		view.animate(animation);
	}
});

view.addEventListener('click', function(e) {
	view.animate(animation);
});
Stack trace:
E/AndroidRuntime(  421): FATAL EXCEPTION: main
E/AndroidRuntime(  421): java.lang.NullPointerException
E/AndroidRuntime(  421): 	at org.appcelerator.titanium.view.Ti2DMatrix.interpolate(Ti2DMatrix.java:187)
E/AndroidRuntime(  421): 	at org.appcelerator.titanium.util.TiAnimationBuilder$TiMatrixAnimation.applyTransformation(TiAnimationBuilder.java:416)
E/AndroidRuntime(  421): 	at android.view.animation.AnimationSet.initializeInvalidateRegion(AnimationSet.java:286)
E/AndroidRuntime(  421): 	at android.view.ViewGroup.drawChild(ViewGroup.java:1498)
E/AndroidRuntime(  421): 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
E/AndroidRuntime(  421): 	at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
E/AndroidRuntime(  421): 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
E/AndroidRuntime(  421): 	at android.view.View.draw(View.java:6743)
E/AndroidRuntime(  421): 	at android.widget.FrameLayout.draw(FrameLayout.java:352)
E/AndroidRuntime(  421): 	at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
E/AndroidRuntime(  421): 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
E/AndroidRuntime(  421): 	at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
E/AndroidRuntime(  421): 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
E/AndroidRuntime(  421): 	at android.view.View.draw(View.java:6743)
E/AndroidRuntime(  421): 	at android.widget.FrameLayout.draw(FrameLayout.java:352)
E/AndroidRuntime(  421): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1842)
E/AndroidRuntime(  421): 	at android.view.ViewRoot.draw(ViewRoot.java:1407)
E/AndroidRuntime(  421): 	at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
E/AndroidRuntime(  421): 	at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
E/AndroidRuntime(  421): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  421): 	at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  421): 	at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(  421): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  421): 	at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  421): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(  421): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(  421): 	at dalvik.system.NativeStart.main(Native Method)
I tried to simplify the test case by removing the complete handler, so there's only a single animation: however, for some reason I can't get the animation to run at all in that case.

Comments

  1. Mauro Parra-Miranda 2012-02-02

    Community Discussion: http://developer.appcelerator.com/question/131556/animation-in-andriod-app-not-working
  2. Natalie Huynh 2012-02-06

    Tested with 1.9.0.v20120206143134 on Kindle Fire and Emulator 2.2 no longer encountering the crash, see linked bug for the animation problem
  3. jithinpv 2013-11-27

    Anvil test case added. PR link: https://github.com/appcelerator/titanium_mobile/pull/5037

JSON Source