@@ -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
0 commit comments