SDL_CreateWindowFrom double-allocate bug

I discovered yesterday that it’s possible to successfully call SDL_CreateWindowFrom on the same HWND handle twice. This leads to all sorts of strange (undefined?) behavior and generally results in crashes eventually. I can think of two ways to fix this. In both cases, when you call SDL_CreateWindowFrom, before the line = _this->next_object_id++;
scan the “windows” array to see if any existing window already has the handle you passed in. If so, either

  1. Call SDL_SetError and return 0 or
  2. Return the existing window.

Personally, I prefer the first option, since any code trying to create a SDL window over an existing one probably has bugs, and an explicit failure will help the debugging process, assuming it checks the return code.