Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash in runAnimationStep on OnePlus and Oppo devices #37487

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

package com.facebook.react.animated;

import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.build.ReactBuildConfig;

/**
* Implementation of {@link AnimationDriver} which provides a support for simple time-based
Expand Down Expand Up @@ -70,7 +73,14 @@ public void runAnimationStep(long frameTimeNanos) {
long timeFromStartMillis = (frameTimeNanos - mStartFrameTimeNanos) / 1000000;
int frameIndex = (int) Math.round(timeFromStartMillis / FRAME_TIME_MILLIS);
if (frameIndex < 0) {
throw new IllegalStateException("Calculated frame index should never be lower than 0");
String message = "Calculated frame index should never be lower than 0. Called with frameTimeNanos " +
frameTimeNanos + " and mStartFrameTimeNanos " + mStartFrameTimeNanos;
if (ReactBuildConfig.DEBUG) {
throw new IllegalStateException(message);
} else {
FLog.w(ReactConstants.TAG, message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure how this fixes given that frameIndex will then be negative by then and it's used below to index access an array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just returns early to make sure no other effects of this function run (see line 82):

https://github.com/facebook/react-native/pull/37487/files#diff-16ce46a8c2c1aa9e045a19ea56f11d5043172f9086bc910adb15585bf08a830bR82

Does that work? I think it should be fairly safe since we basically pretend that this animation shouldn't have its frame change, which should be a no-op.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just returns early

You're so right :) I missed that line

return;
}
} else if (mHasFinished) {
// nothing to do here
return;
Expand Down