Skip to content

Commit 028ae38

Browse files
committed
Don't forward calls to close or setParent during shutdown
Also mark the related variables as volatile because they may be accessed from multiple threads.
1 parent 61c6850 commit 028ae38

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

java/org/cef/browser/CefBrowser_N.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser {
4646
private Point inspectAt_ = null;
4747
private CefBrowser_N devTools_ = null;
4848
private boolean closeAllowed_ = false;
49-
private boolean isClosed_ = false;
49+
private volatile boolean isClosed_ = false;
50+
private volatile boolean isClosing_ = false;
5051

5152
protected CefBrowser_N(CefClient client, String url, CefRequestContext context,
5253
CefBrowser_N parent, Point inspectAt) {
@@ -434,6 +435,9 @@ public String getURL() {
434435

435436
@Override
436437
public void close(boolean force) {
438+
if (isClosing_ || isClosed_) return;
439+
if (force) isClosing_ = true;
440+
437441
try {
438442
N_Close(force);
439443
} catch (UnsatisfiedLinkError ule) {
@@ -720,6 +724,8 @@ protected final void updateUI(Rectangle contentRect, Rectangle browserRect) {
720724
}
721725

722726
protected final void setParent(long windowHandle, Component canvas) {
727+
if (isClosing_ || isClosed_) return;
728+
723729
try {
724730
N_SetParent(windowHandle, canvas);
725731
} catch (UnsatisfiedLinkError ule) {

java/tests/detailed/BrowserFrame.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.cef.handler.CefLifeSpanHandlerAdapter;
1515

1616
public class BrowserFrame extends JFrame {
17-
private boolean isClosed_ = false;
17+
private volatile boolean isClosed_ = false;
1818
private CefBrowser browser_ = null;
1919
private static int browserCount_ = 0;
2020
private Runnable afterParentChangedAction_ = null;

0 commit comments

Comments
 (0)