Destroying windows from SDL_CreateWindowFrom

(SDL 2.0.5, windows 10)

In my application I’m using SDL_CreateWindowFrom since I’m developing a plugin and I am given a native window handle to do what I want with it (specifically, I’m using this for VST3 plugins)

At some point I get notified that the (native) window got closed.
At that point I want to free my resources.
The problem is that upon calling SDL_DestroyWindow the application hangs. It hangs at the point of calling SDL_HideWindow which then itself calls

    if (_this->HideWindow) {
        _this->HideWindow(_this, window);
    }

which then calls

void
WIN_HideWindow(_THIS, SDL_Window * window)
{
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
    ShowWindow(hwnd, SW_HIDE);
}

And this is where it hangs.

Do I have some misconception about destroying the window? Do somehow the resources get freed by SDL and I shouldn’t call SDL_DestroyWindow?

If not, it appears that the solutions I have right now would be one of the following:

  • fork and not call hide window if it’s the SDL_WINDOW_FOREIGN is set
  • include the definition of SDL_Window to modify myself the SDL_WINDOW_SHOWN (which is checked before proceeding the actual HideWindow calls

I had the exact same issue when I was calling SDL_DestroyWindow from a worker thread. Looks like the Create and Destroy calls need to be done on the app main thread.