Skip to content

Commit f091c2a

Browse files
mkartashevjbrbot
authored andcommitted
JBR-9772 Ubuntu + Wayland: SIGSEGV at Java_sun_awt_wl_GtkFrameDecoration_nativeNotifyConfigured
1 parent 728a4d2 commit f091c2a

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

src/java.desktop/unix/classes/sun/awt/wl/GtkFrameDecoration.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class GtkFrameDecoration extends FullFrameDecorationHelper {
5151
private static final int CLOSE_BUTTON_STATE_HOVERED = 1 << 4;
5252
private static final int CLOSE_BUTTON_STATE_PRESSED = 1 << 5;
5353

54-
private long nativePtr;
54+
private long nativePtr; // accessed under AWT lock
5555
private Rectangle minimizeButtonBounds; // set by the native code
5656
private Rectangle maximizeButtonBounds; // set by the native code
5757
private Rectangle closeButtonBounds; // set by the native code
@@ -75,8 +75,16 @@ public GtkFrameDecoration(WLDecoratedPeer peer, boolean showMinimize, boolean sh
7575

7676
@Override
7777
public void paint(Graphics g) {
78-
// Determine buttons' bounds, etc.
79-
nativePrePaint(nativePtr, peer.getWidth(), peer.getHeight());
78+
WLToolkit.awtLock();
79+
try {
80+
if (nativePtr == 0) return;
81+
82+
// Determine buttons' bounds, etc.
83+
nativePrePaint(nativePtr, peer.getWidth(), peer.getHeight());
84+
} finally {
85+
WLToolkit.awtUnlock();
86+
}
87+
8088
if (peer.getWidth() >= titleBarMinWidth && peer.getHeight() >= titleBarHeight) {
8189
super.paint(g);
8290
}
@@ -96,10 +104,16 @@ protected void paintTitleBar(Graphics2D g2d) {
96104
int nativeW = (int) Math.ceil(width * scale);
97105
int nativeH = (int) Math.ceil(height * scale);
98106
DataBufferInt dataBuffer = new DataBufferInt(nativeW * nativeH);
99-
nativePaintTitleBar(
100-
nativePtr,
101-
SunWritableRaster.stealData(dataBuffer, 0),
102-
width, height, scale, peer.getTitle(), getButtonsState());
107+
WLToolkit.awtLock();
108+
try {
109+
if (nativePtr == 0 ) return;
110+
nativePaintTitleBar(
111+
nativePtr,
112+
SunWritableRaster.stealData(dataBuffer, 0),
113+
width, height, scale, peer.getTitle(), getButtonsState());
114+
} finally {
115+
WLToolkit.awtUnlock();
116+
}
103117
SunWritableRaster.markDirty(dataBuffer);
104118
int[] bands = {0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000};
105119
WritableRaster raster = Raster.createPackedRaster(dataBuffer, nativeW, nativeH, nativeW, bands, null);
@@ -120,8 +134,15 @@ protected void paintBorder(Graphics2D g2d) {
120134

121135
@Override
122136
public void dispose() {
123-
nativeDestroyDecoration(nativePtr);
124-
nativePtr = 0;
137+
WLToolkit.awtLock();
138+
try {
139+
if (nativePtr != 0) {
140+
nativeDestroyDecoration(nativePtr);
141+
nativePtr = 0;
142+
}
143+
} finally {
144+
WLToolkit.awtUnlock();
145+
}
125146
super.dispose();
126147
}
127148

@@ -168,8 +189,12 @@ public Dimension getMinimumSize() {
168189

169190
@Override
170191
public void notifyConfigured(boolean active, boolean maximized, boolean fullscreen) {
171-
nativeNotifyConfigured(nativePtr, active, maximized, fullscreen);
172-
super.notifyConfigured(active, maximized, fullscreen);
192+
assert WLToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
193+
// The frame may have been hidden by the time the "configured" event has reached us here
194+
if (nativePtr != 0) {
195+
nativeNotifyConfigured(nativePtr, active, maximized, fullscreen);
196+
super.notifyConfigured(active, maximized, fullscreen);
197+
}
173198
}
174199

175200
@Override

src/java.desktop/unix/classes/sun/awt/wl/WLDecoratedPeer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package sun.awt.wl;
2626

27+
import sun.awt.SunToolkit;
28+
2729
import java.awt.Cursor;
2830
import java.awt.Dimension;
2931
import java.awt.Graphics;
@@ -185,6 +187,8 @@ void postMouseEvent(MouseEvent e) {
185187
@Override
186188
void notifyConfigured(int newSurfaceX, int newSurfaceY, int newSurfaceWidth, int newSurfaceHeight,
187189
boolean active, boolean maximized, boolean fullscreen) {
190+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
191+
188192
boolean wasFullscreen = isFullscreen();
189193

190194
super.notifyConfigured(newSurfaceX, newSurfaceY, newSurfaceWidth, newSurfaceHeight,

0 commit comments

Comments
 (0)