example: ++gl, wgpu safety

Free the canvas in the reverse order of their creation.
This commit is contained in:
Hermet Park 2024-11-25 11:02:16 +09:00 committed by Hermet Park
parent 8995bc32a2
commit 036d1e7cac

View file

@ -338,6 +338,10 @@ struct GlWindow : Window
virtual ~GlWindow() virtual ~GlWindow()
{ {
//Free in the reverse order of their creation.
delete(canvas);
canvas = nullptr;
SDL_GL_DeleteContext(context); SDL_GL_DeleteContext(context);
} }
@ -425,8 +429,10 @@ struct WgWindow : Window
virtual ~WgWindow() virtual ~WgWindow()
{ {
//the canvas is tightly relying on the wgpu resource. cut out before rleasing them for safety. //Free in the reverse order of their creation.
static_cast<tvg :: WgCanvas*>(canvas)->target(nullptr, nullptr, nullptr, 0, 0); delete(canvas);
canvas = nullptr;
wgpuSurfaceRelease(surface); wgpuSurfaceRelease(surface);
wgpuInstanceRelease(instance); wgpuInstanceRelease(instance);
} }