Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit f567fff

Browse files
MortimerGorokeianhzo
authored andcommitted
Handle potential exception capturing snapshots (#2386)
* Handle potential exception when GeckoSession.capture() is called * Reset the mCaptureOnPageStop member when switching sessions
1 parent d6f46c4 commit f567fff

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -474,15 +474,25 @@ public void captureBitmap() {
474474
if (mState.mDisplay == null || !mFirstContentfulPaint) {
475475
return;
476476
}
477-
mState.mDisplay.screenshot().aspectPreservingSize(500).capture().then(bitmap -> {
478-
if (bitmap != null) {
479-
BitmapCache.getInstance(mContext).addBitmap(getId(), bitmap);
480-
for (BitmapChangedListener listener: mBitmapChangedListeners) {
481-
listener.onBitmapChanged(Session.this, bitmap);
477+
try {
478+
mState.mDisplay.screenshot().aspectPreservingSize(500).capture().then(bitmap -> {
479+
if (bitmap != null) {
480+
BitmapCache.getInstance(mContext).addBitmap(getId(), bitmap);
481+
for (BitmapChangedListener listener: mBitmapChangedListeners) {
482+
listener.onBitmapChanged(Session.this, bitmap);
483+
}
482484
}
483-
}
484-
return null;
485-
});
485+
return null;
486+
}).exceptionally(throwable -> {
487+
Log.e(LOGTAG, "Error capturing session bitmap");
488+
throwable.printStackTrace();
489+
return null;
490+
});
491+
} catch (Exception ex) {
492+
Log.e(LOGTAG, "Error capturing session bitmap");
493+
ex.printStackTrace();
494+
}
495+
486496
}
487497

488498
public CompletableFuture<Void> captureBackgroundBitmap(int displayWidth, int displayHeight) {
@@ -497,19 +507,38 @@ public CompletableFuture<Void> captureBackgroundBitmap(int displayWidth, int dis
497507
CompletableFuture<Void> result = new CompletableFuture<>();
498508
GeckoDisplay display = mState.mSession.acquireDisplay();
499509
display.surfaceChanged(captureSurface, displayWidth, displayHeight);
500-
display.screenshot().aspectPreservingSize(500).capture().then(bitmap -> {
501-
if (bitmap != null) {
502-
BitmapCache.getInstance(mContext).addBitmap(getId(), bitmap);
503-
for (BitmapChangedListener listener: mBitmapChangedListeners) {
504-
listener.onBitmapChanged(Session.this, bitmap);
505-
}
506-
}
510+
511+
Runnable cleanResources = () -> {
507512
display.surfaceDestroyed();
508513
mState.mSession.releaseDisplay(display);
509514
BitmapCache.getInstance(mContext).releaseCaptureSurface();
515+
};
516+
517+
try {
518+
display.screenshot().aspectPreservingSize(500).capture().then(bitmap -> {
519+
if (bitmap != null) {
520+
BitmapCache.getInstance(mContext).addBitmap(getId(), bitmap);
521+
for (BitmapChangedListener listener : mBitmapChangedListeners) {
522+
listener.onBitmapChanged(Session.this, bitmap);
523+
}
524+
}
525+
cleanResources.run();
526+
result.complete(null);
527+
return null;
528+
}).exceptionally(throwable -> {
529+
Log.e(LOGTAG, "Error capturing session background bitmap");
530+
throwable.printStackTrace();
531+
cleanResources.run();
532+
result.complete(null);
533+
return null;
534+
});
535+
}
536+
catch (Exception ex) {
537+
Log.e(LOGTAG, "Error capturing session background bitmap");
538+
ex.printStackTrace();
539+
cleanResources.run();
510540
result.complete(null);
511-
return null;
512-
});
541+
}
513542
return result;
514543
}
515544

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,7 @@ public void setSession(@NonNull Session aSession, @OldSessionDisplayAction int a
10751075
listener.onSessionChanged(oldSession, aSession);
10761076
}
10771077
}
1078+
mCaptureOnPageStop = false;
10781079
hideLibraryPanels();
10791080
}
10801081

0 commit comments

Comments
 (0)