diff --git a/binding/osfm-screen-binding.cpp b/binding/osfm-screen-binding.cpp index 43791207d..11b911d03 100644 --- a/binding/osfm-screen-binding.cpp +++ b/binding/osfm-screen-binding.cpp @@ -339,6 +339,9 @@ RB_METHOD(monitorWindowInit) { int w = NUM2INT(vw); int h = NUM2INT(vh); + if (w < 1 || h < 1) + rb_raise(rb_eArgError, "Invalid window size"); + const char* name = " "; unsigned int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_UTILITY | SDL_WINDOW_BORDERLESS | SDL_WINDOW_TRANSPARENT; if (!NIL_P(kwargs)) { @@ -395,11 +398,11 @@ RB_METHOD(monitorWindowResize) { int w, h; rb_get_args(argc, argv, "ii", &w, &h RB_ARG_END); - window->scene.resize(w, h); + if (w < 1 || h < 1) + rb_raise(rb_eArgError, "Invalid window size"); SDL_SetWindowSize(window->window, w, h); - - GFX_UNLOCK; + window->scene.resize(w, h); return Qnil; } diff --git a/src/eventthread.cpp b/src/eventthread.cpp index 944d3b7b5..0fff18ead 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -113,6 +113,7 @@ enum REQUEST_SETTINGS, REQUEST_NEW_WINDOW, REQUEST_DESTROY_WINDOW, + REQUEST_WINDOW_VISIBLE, UPDATE_FPS, UPDATE_SCREEN_RECT, @@ -615,6 +616,15 @@ void EventThread::process(RGSSThreadData &rtData) SDL_DestroyWindow(static_cast(event.user.data1)); break; } + case REQUEST_WINDOW_VISIBLE: + { + SDL_Window *window = static_cast(event.user.data1); + if (event.user.data2) + SDL_ShowWindow(window); + else + SDL_HideWindow(window); + break; + } case UPDATE_FPS : if (rtData.config.printFPS) @@ -869,9 +879,23 @@ SDL_Window *EventThread::requestNewWindow(const CreateWindowArgs *args) new_window = nullptr; // reset SDL_PushEvent(&event); while (!new_window) - SDL_Delay(1); + // we want to delay ~0.1ms + // ideally the delay should be long enough that the window is created in one loop, + // but short enough that we aren't waiting for a long time after the window is created + SDL_DelayNS(10000); return (SDL_Window*) new_window; } + +void EventThread::requestWindowVisible(SDL_Window *window, bool visible) +{ + SDL_Event event; + event.type = usrIdStart + REQUEST_WINDOW_VISIBLE; + event.user.data1 = window; + event.user.data2 = (void*) visible; + + SDL_PushEvent(&event); +} + void EventThread::destroySDLWindow(SDL_Window *window) { SDL_Event event; diff --git a/src/eventthread.h b/src/eventthread.h index dec253d25..349550072 100644 --- a/src/eventthread.h +++ b/src/eventthread.h @@ -104,18 +104,19 @@ class EventThread // get random freezes without doing this on the event thread SDL_Window* requestNewWindow(const CreateWindowArgs *args); void destroySDLWindow(SDL_Window *window); + void requestWindowVisible(SDL_Window *window, bool visible); - void requestTextInputMode(bool mode); - - void requestSettingsMenu(); + void requestTextInputMode(bool mode); + + void requestSettingsMenu(); void requestTerminate(); bool getFullscreen() const; bool getShowCursor() const; - bool getControllerConnected() const; - - SDL_Gamepad *controller() const; + bool getControllerConnected() const; + + SDL_Gamepad *controller() const; void showMessageBox(const char *body, int flags = 0); diff --git a/src/main.cpp b/src/main.cpp index fafc2a950..7a879d268 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -574,8 +574,10 @@ static SDL_GLContext initGL(SDL_Window *win, Config &conf, printGLInfo(); - bool vsync = conf.vsync || conf.syncToRefreshrate; - SDL_GL_SetSwapInterval(vsync ? 1 : 0); + //bool vsync = conf.vsync || conf.syncToRefreshrate; + // SDL_GL_SetSwapInterval(vsync ? 1 : 0); + // For various reasons, we don't want vsync. So, we just force it off for now. + SDL_GL_SetSwapInterval(0); // GLDebugLogger dLogger; return glCtx;