fix, not unregister gpu texture when closeSession is false (#8018)

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2024-05-11 11:11:12 +08:00 committed by GitHub
parent 0152e937ec
commit 712bfbae92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -102,13 +102,15 @@ class _GpuTexture {
}
}
destroy(FFI ffi) async {
destroy(bool unregisterTexture, FFI ffi) async {
// must stop texture render, render unregistered texture cause crash
if (!_destroying && support && _sessionId != null && _textureId != -1) {
_destroying = true;
if (unregisterTexture) {
platformFFI.registerGpuTexture(_sessionId!, _display, 0);
// sleep for a while to avoid the texture is used after it's unregistered.
await Future.delayed(Duration(milliseconds: 100));
}
await gpuTextureRenderer.unregisterTexture(_textureId);
_textureId = -1;
_destroying = false;
@ -208,7 +210,7 @@ class TextureModel {
_pixelbufferRenderTextures.remove(idx);
}
if (_gpuRenderTextures.containsKey(idx)) {
_gpuRenderTextures[idx]!.destroy(ffi);
_gpuRenderTextures[idx]!.destroy(true, ffi);
_gpuRenderTextures.remove(idx);
}
}
@ -235,7 +237,7 @@ class TextureModel {
await texture.destroy(closeSession, ffi);
}
for (final texture in _gpuRenderTextures.values) {
await texture.destroy(ffi);
await texture.destroy(closeSession, ffi);
}
}