Unverified Commit 1f13701d authored by Igor Demin's avatar Igor Demin Committed by GitHub

Merge pull request #73 from JetBrains/fix_dispose

Fix crash when we close the window immediately after its start
parents e93a896b ad499719
...@@ -17,7 +17,7 @@ extern "C" ...@@ -17,7 +17,7 @@ extern "C"
{ {
} }
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_dispose(JNIEnv *env, jobject canvas) JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeDispose(JNIEnv *env, jobject canvas)
{ {
} }
......
...@@ -8,7 +8,7 @@ extern "C" ...@@ -8,7 +8,7 @@ extern "C"
{ {
} }
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_dispose(JNIEnv *env, jobject canvas) JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeDispose(JNIEnv *env, jobject canvas)
{ {
} }
......
...@@ -35,11 +35,21 @@ abstract class HardwareLayer : Canvas() { ...@@ -35,11 +35,21 @@ abstract class HardwareLayer : Canvas() {
protected open fun init() { protected open fun init() {
useDrawingSurfacePlatformInfo(::nativeInit) useDrawingSurfacePlatformInfo(::nativeInit)
onInit()
} }
protected open external fun nativeInit(platformInfo: Long) fun dispose() {
if (isInit) {
onDispose()
nativeDispose()
}
}
protected open fun onInit() = Unit
protected open fun onDispose() = Unit
open external fun dispose() private external fun nativeInit(platformInfo: Long)
private external fun nativeDispose()
protected open fun contentScaleChanged() = Unit protected open fun contentScaleChanged() = Unit
......
...@@ -36,8 +36,8 @@ open class SkiaLayer( ...@@ -36,8 +36,8 @@ open class SkiaLayer(
private val pictureRecorder = PictureRecorder() private val pictureRecorder = PictureRecorder()
private val pictureLock = Any() private val pictureLock = Any()
override fun init() { override fun onInit() {
super.init() super.onInit()
val initialRenderApi = fallbackRenderApiQueue.removeAt(0) val initialRenderApi = fallbackRenderApiQueue.removeAt(0)
contextHandler = createContextHandler(this, initialRenderApi) contextHandler = createContextHandler(this, initialRenderApi)
redrawer = platformOperations.createRedrawer(this, initialRenderApi, properties) redrawer = platformOperations.createRedrawer(this, initialRenderApi, properties)
...@@ -45,15 +45,15 @@ open class SkiaLayer( ...@@ -45,15 +45,15 @@ open class SkiaLayer(
redraw() redraw()
} }
override fun dispose() { override fun onDispose() {
check(!isDisposed) check(!isDisposed)
check(isEventDispatchThread()) check(isEventDispatchThread())
redrawer?.dispose() // we should dispose redrawer first (to cancel `draw` in rendering thread)
contextHandler?.dispose() contextHandler?.dispose()
redrawer?.dispose()
picture?.instance?.close() picture?.instance?.close()
pictureRecorder.close() pictureRecorder.close()
isDisposed = true isDisposed = true
super.dispose() super.onDispose()
} }
override fun setBounds(x: Int, y: Int, width: Int, height: Int) { override fun setBounds(x: Int, y: Int, width: Int, height: Int) {
......
...@@ -112,7 +112,7 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeInit(JNIEnv ...@@ -112,7 +112,7 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeInit(JNIEnv
[layerStorage addObject: layersSet]; [layerStorage addObject: layersSet];
} }
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_dispose(JNIEnv *env, jobject canvas) JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeDispose(JNIEnv *env, jobject canvas)
{ {
LayerHandler *layer = findByObject(env, canvas); LayerHandler *layer = findByObject(env, canvas);
if (layer != NULL) if (layer != NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment