Skip to content

Commit ddbf108

Browse files
committed
⬆️ vkk
small fixed to LwjglCanvas
1 parent e1398a9 commit ddbf108

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

uno-awt/src/main/kotlin/uno/awt/LwjglCanvas.kt

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ import uno.glfw.HWND
1111
import uno.glfw.VSync
1212
import uno.glfw.glfw
1313
import java.awt.Canvas
14+
import java.awt.EventQueue
1415
import java.awt.Graphics
1516
import java.awt.event.ComponentAdapter
1617
import java.awt.event.ComponentEvent
17-
import java.lang.reflect.InvocationTargetException
18-
import javax.swing.SwingUtilities
1918

2019

2120
/**
@@ -107,7 +106,9 @@ abstract class LwjglCanvas(val glDebug: Boolean = false) : Canvas() {
107106
// }
108107
})
109108

110-
SwingUtilities.invokeAndWait {
109+
if (EventQueue.isDispatchThread())
110+
surface = awt.getDrawingSurface(this)!!
111+
else EventQueue.invokeAndWait {
111112
surface = awt.getDrawingSurface(this)!!
112113
}
113114
}
@@ -309,30 +310,16 @@ abstract class LwjglCanvas(val glDebug: Boolean = false) : Canvas() {
309310

310311
animated = animate
311312

312-
if (animate) {
313-
314-
if (SwingUtilities.isEventDispatchThread()) {
315-
val g = graphics
316-
if (g != null) {
313+
if (animate)
314+
graphics?.let { g ->
315+
if (EventQueue.isDispatchThread()) {
316+
paint(g)
317+
g.dispose()
318+
} else EventQueue.invokeAndWait {
317319
paint(g)
318320
g.dispose()
319-
}
320-
} else {
321-
try {
322-
SwingUtilities.invokeAndWait {
323-
val g = graphics
324-
if (g != null) {
325-
paint(g)
326-
g.dispose()
327-
}
328-
}
329-
} catch (ex: InterruptedException) {
330-
println("Exception while starting viewer animation")
331-
} catch (ex: InvocationTargetException) {
332-
println("Exception while starting viewer animation")
333321
}
334322
}
335-
}
336323
}
337324
}
338325

uno-awt/src/main/kotlin/uno/awt/helpers.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ fun JAWT.getDrawingSurface(canvas: Canvas): JAWTDrawingSurface? {
3232
return JAWTDrawingSurface.createSafe(result)
3333
}
3434

35+
36+
3537
inline class JawtLock(val int: Int) {
3638
companion object {
3739
val ERROR = JawtLock(0x1)

0 commit comments

Comments
 (0)