Skip to content

Emscripten resize doesn't work with SDL_SetWindowResizable() #12405

@esotericpig

Description

@esotericpig

I'm using SDL2 and found quite a strange bug.

I set up my window like this for my desktop app:

window = SDL_CreateWindow(
  title_.c_str(),SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,config.size.w,config.size.h,
  SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI
);

// The SDL_WINDOW_RESIZABLE flag in SDL_CreateWindow() increases the size for some reason
// (even w/o SDL_WINDOW_ALLOW_HIGHDPI), but this explicit call doesn't.
SDL_SetWindowResizable(window,SDL_TRUE);

This was to fix a bug already for my system. For some reason, if I added | SDL_WINDOW_RESIZABLE, it would increase my requested window size from 1600x900 to something slightly bigger. This is on Linux.

Anyway, I ported my game to Emscripten, using the same code. I handle SDL2 resize events. However, whenever I would resize the browser window, I wouldn't receive any window resize events. Finally, after racking my brain over it and trying different things, I finally went to the code at SDL_emscriptenevents.c#Emscripten_HandleResize(). I saw the line window_data->window->flags & SDL_WINDOW_RESIZABLE, and decided to add that to SDL_CreateWindow(), even though SDL_SetWindowResizable() should already add it.

And voila, it works!

So I basically have to do this:

#if defined(__EMSCRIPTEN__)

  window = SDL_CreateWindow(
    title_.c_str(),SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,config.size.w,config.size.h,
    SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE
  );

#else

  window = SDL_CreateWindow(
    title_.c_str(),SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,config.size.w,config.size.h,
    SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI
  );

  SDL_SetWindowResizable(window,SDL_TRUE);

#endif

It seems as though SDL_SetWindowResizable() doesn't work with Emscripten for some reason.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions