Skip to content

Commit

Permalink
Fix "Show Perf Monitor" crash in Catalyst (#41926)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #41926

"Show Perf Monitor" is crashing due to some methods in FpsDebugFrameCallback.java calls bridge-only methods.

Changelog:
[Android][Changed] - Fix "Show Perf Monitor" crash in Catalyst

Reviewed By: cortinico

Differential Revision: D52053678

fbshipit-source-id: 1a49ce6e9bb77cc07ceb796c5cacec179dba946d
  • Loading branch information
Lulu Wu authored and facebook-github-bot committed Dec 13, 2023
1 parent 5217cc9 commit 6f11511
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public FpsInfo(

public FpsDebugFrameCallback(ReactContext reactContext) {
mReactContext = reactContext;
mUIManagerModule =
Assertions.assertNotNull(reactContext.getNativeModule(UIManagerModule.class));
mUIManagerModule = reactContext.getNativeModule(UIManagerModule.class);
mDidJSUpdateUiDuringFrameDetector = new DidJSUpdateUiDuringFrameDetector();
}

Expand Down Expand Up @@ -125,10 +124,16 @@ public void start() {
}

public void start(double targetFps) {
mReactContext
.getCatalystInstance()
.addBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector);
mUIManagerModule.setViewHierarchyUpdateDebugListener(mDidJSUpdateUiDuringFrameDetector);
// T172641976: re-think if we need to implement addBridgeIdleDebugListener and
// removeBridgeIdleDebugListener for Bridgeless
if (!mReactContext.isBridgeless()) {
mReactContext
.getCatalystInstance()
.addBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector);
}
if (mUIManagerModule != null) {
mUIManagerModule.setViewHierarchyUpdateDebugListener(mDidJSUpdateUiDuringFrameDetector);
}
mTargetFps = targetFps;
UiThreadUtil.runOnUiThread(
() -> {
Expand All @@ -144,10 +149,14 @@ public void startAndRecordFpsAtEachFrame() {
}

public void stop() {
mReactContext
.getCatalystInstance()
.removeBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector);
mUIManagerModule.setViewHierarchyUpdateDebugListener(null);
if (!mReactContext.isBridgeless()) {
mReactContext
.getCatalystInstance()
.removeBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector);
}
if (mUIManagerModule != null) {
mUIManagerModule.setViewHierarchyUpdateDebugListener(null);
}
UiThreadUtil.runOnUiThread(
() -> {
mChoreographer = Choreographer.getInstance();
Expand Down

0 comments on commit 6f11511

Please sign in to comment.