Skip to content

Commit a949af6

Browse files
committed
bug fix: making sue that calls happen in the EDT
1 parent 1a3aa40 commit a949af6

File tree

1 file changed

+62
-37
lines changed

1 file changed

+62
-37
lines changed

src/java/cleargl/ClearGLWindow.java

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -189,24 +189,28 @@ public void stop()
189189
@Override
190190
public void close() throws GLException
191191
{
192-
try
193-
{
194-
try
195-
{
196-
mGlWindow.setVisible(false);
197-
mGlWindow.removeGLEventListener(mClearGLWindowEventListener);
198-
}
199-
catch (final Throwable e)
200-
{
201-
System.err.println(e.getLocalizedMessage());
202-
}
203-
if (mGlWindow.isRealized())
204-
mGlWindow.destroy();
205-
}
206-
catch (final Throwable e)
207-
{
208-
System.err.println(e.getLocalizedMessage());
209-
}
192+
runOnEDT( true,
193+
() -> {
194+
try
195+
{
196+
try
197+
{
198+
mGlWindow.setVisible(false);
199+
mGlWindow.removeGLEventListener(mClearGLWindowEventListener);
200+
}
201+
catch (final Throwable e)
202+
{
203+
System.err.println(e.getLocalizedMessage());
204+
}
205+
if (mGlWindow.isRealized())
206+
mGlWindow.destroy();
207+
}
208+
catch (final Throwable e)
209+
{
210+
System.err.println(e.getLocalizedMessage());
211+
}
212+
});
213+
210214
}
211215

212216
/* (non-Javadoc)
@@ -215,7 +219,9 @@ public void close() throws GLException
215219
@Override
216220
public void setWindowTitle(final String pTitleString)
217221
{
218-
mGlWindow.setTitle(pTitleString);
222+
runOnEDT(false, () -> {
223+
mGlWindow.setTitle(pTitleString);
224+
});
219225
}
220226

221227
/* (non-Javadoc)
@@ -224,7 +230,16 @@ public void setWindowTitle(final String pTitleString)
224230
@Override
225231
public void setVisible(final boolean pIsVisible)
226232
{
227-
mGlWindow.setVisible(pIsVisible);
233+
runOnEDT(false, () -> {
234+
mGlWindow.setVisible(pIsVisible);
235+
});
236+
}
237+
238+
public void requestFocus()
239+
{
240+
runOnEDT(false, () -> {
241+
mGlWindow.requestFocus();
242+
});
228243
}
229244

230245
/* (non-Javadoc)
@@ -233,23 +248,28 @@ public void setVisible(final boolean pIsVisible)
233248
@Override
234249
public void toggleFullScreen()
235250
{
236-
try
237-
{
238-
if (mGlWindow.isFullscreen())
239-
{
240-
mGlWindow.setFullscreen(false);
241-
}
242-
else
243-
{
244-
mGlWindow.setSize(mWindowDefaultWidth, mWindowDefaultHeight);
245-
mGlWindow.setFullscreen(true);
246-
}
247-
mGlWindow.display();
248-
}
249-
catch (final Exception e)
250-
{
251-
e.printStackTrace();
252-
}
251+
runOnEDT( false,
252+
() -> {
253+
try
254+
{
255+
if (mGlWindow.isFullscreen())
256+
{
257+
mGlWindow.setFullscreen(false);
258+
}
259+
else
260+
{
261+
mGlWindow.setSize(mWindowDefaultWidth,
262+
mWindowDefaultHeight);
263+
mGlWindow.setFullscreen(true);
264+
}
265+
mGlWindow.display();
266+
}
267+
catch (final Exception e)
268+
{
269+
e.printStackTrace();
270+
}
271+
});
272+
253273
}
254274

255275
/* (non-Javadoc)
@@ -517,4 +537,9 @@ public GLAutoDrawable getGLAutoDrawable()
517537
return mGlWindow;
518538
}
519539

540+
public void runOnEDT(boolean pWait, Runnable pRunnable)
541+
{
542+
mGlWindow.runOnEDTIfAvail(pWait, pRunnable);
543+
}
544+
520545
}

0 commit comments

Comments
 (0)