Skip to content

Commit

Permalink
Fix possible hierarchy corruption by postponing dispose call
Browse files Browse the repository at this point in the history
  • Loading branch information
MatkovIvan committed Feb 21, 2024
1 parent 6c3405a commit fff3e56
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import java.awt.event.FocusEvent
import java.awt.event.FocusListener
import java.util.*
import javax.swing.JLayeredPane
import javax.swing.SwingUtilities
import javax.swing.SwingUtilities.isEventDispatchThread
import org.jetbrains.skiko.GraphicsApi
import org.jetbrains.skiko.SkiaLayerAnalytics
Expand Down Expand Up @@ -235,7 +236,13 @@ class ComposePanel @ExperimentalComposeUiApi constructor(
override fun removeNotify() {
_composeContainer?.removeNotify()
if (isDisposeOnRemove) {
dispose()

// [dispose] might trigger hierarchy change for example removing [LayerType.OnComponent]
// layers. That will conflict with removing this [ComposePanel]. To avoid such
// issues we need to call [dispose] after leaving this method.
SwingUtilities.invokeLater {
dispose()
}
}
super.removeNotify()
}
Expand Down

0 comments on commit fff3e56

Please sign in to comment.