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

Fix FpsDebugFrameCallback so that we properly cancel frame loop to avoid race #38671

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 @@ -63,7 +63,6 @@ public FpsInfo(
private final UIManagerModule mUIManagerModule;
private final DidJSUpdateUiDuringFrameDetector mDidJSUpdateUiDuringFrameDetector;

private boolean mShouldStop = false;
private long mFirstFrameTime = -1;
private long mLastFrameTime = -1;
private int mNumFrameCallbacks = 0;
Expand All @@ -82,10 +81,6 @@ public FpsDebugFrameCallback(ReactContext reactContext) {

@Override
public void doFrame(long l) {
if (mShouldStop) {
return;
}

if (mFirstFrameTime == -1) {
mFirstFrameTime = l;
}
Expand Down Expand Up @@ -124,7 +119,6 @@ public void doFrame(long l) {
}

public void start() {
mShouldStop = false;
mReactContext
.getCatalystInstance()
.addBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector);
Expand All @@ -147,11 +141,19 @@ public void startAndRecordFpsAtEachFrame() {
}

public void stop() {
mShouldStop = true;
mReactContext
.getCatalystInstance()
.removeBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector);
mUIManagerModule.setViewHierarchyUpdateDebugListener(null);
final FpsDebugFrameCallback fpsDebugFrameCallback = this;
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
mChoreographer = ChoreographerCompat.getInstance();
mChoreographer.removeFrameCallback(fpsDebugFrameCallback);
}
});
}

public double getFPS() {
Expand Down