Skip to content

example: gurantee destroying user data before canvas destruction#29

Merged
hermet merged 1 commit intomainfrom
hermet/hotfix
Mar 12, 2026
Merged

example: gurantee destroying user data before canvas destruction#29
hermet merged 1 commit intomainfrom
hermet/hotfix

Conversation

@hermet
Copy link
Member

@hermet hermet commented Mar 12, 2026

No description provided.

@hermet hermet self-assigned this Mar 12, 2026
Copilot AI review requested due to automatic review settings March 12, 2026 15:56
@hermet hermet added the refactoring Code refactoring / Exceptional handles label Mar 12, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts teardown order in the example window backends so user Example state is destroyed before the ThorVG Canvas, and moves Example/Canvas deletion out of the base Window destructor into backend-specific destructors.

Changes:

  • Remove example/canvas deletion from Window::~Window().
  • Add SwWindow destructor to delete example and canvas.
  • Update GlWindow/WgWindow destructors to delete example before canvas (and remove canvas = nullptr).
Comments suppressed due to low confidence (2)

src/Example.h:180

  • Window::~Window() no longer deletes example/canvas, so any Window subclass that doesn’t implement a destructor to delete them will now leak (e.g., the non-TVGEXAMPLE_WGPU_SUPPORTED WgWindow variant has no destructor). Either restore ownership in Window (with correct ordering relative to backend teardown) or add destructors for every subclass/variant to delete example (and canvas when applicable).
    virtual ~Window()
    {
        //Terminate the SDL
        SDL_DestroyWindow(window);
        SDL_Quit();

        //Terminate ThorVG Engine
        tvg::Initializer::term();
    }

src/Example.h:513

  • WgWindow can early-return from its constructor when !initialized, leaving instance/surface/adapter/device uninitialized. The destructor unconditionally releases all of them, which is undefined behavior if creation didn’t complete. Initialize these handles to nullptr at declaration and guard each wgpu*Release() so it only runs for non-null handles.
    virtual ~WgWindow()
    {
        delete(example);
        delete(canvas);

        wgpuDeviceRelease(device);
        wgpuAdapterRelease(adapter);
        wgpuSurfaceRelease(surface);
        wgpuInstanceRelease(instance);
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hermet hermet merged commit dafee96 into main Mar 12, 2026
6 checks passed
@hermet hermet deleted the hermet/hotfix branch March 12, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Code refactoring / Exceptional handles

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants