Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about window resize in SDL #43

Closed
notchris opened this issue Nov 19, 2023 · 18 comments
Closed

Question about window resize in SDL #43

notchris opened this issue Nov 19, 2023 · 18 comments

Comments

@notchris
Copy link

Awesome library! I was wondering if there is a way to get the event of a window resize during the resize. Currently I notice it only emits on resize complete.

Thanks!

@kmamal
Copy link
Owner

kmamal commented Nov 20, 2023

It looks like this is a problem with Windows itself: libsdl-org/SDL#1059

There are two solutions proposed in that thread. One (main callbacks) is only available in SDL3 which I'm not ready to switch to yet. The other (event watchers) would involve synchronizing threads, so the implementation could get non-trivial. I will try to add this but it could take some time.

@notchris
Copy link
Author

@kmamal TY for the reply! I'm currently on a Macbook M2 Pro. The default behavior is that the render is stretched, I can re-render on the resize event and that cleans things up, but it's a bit jarring.

I looked a bit at some related issues, this thread seems to have varying opinions about a resolution:
https://stackoverflow.com/questions/32294913/getting-continuous-window-resize-event-in-sdl-2

@kmamal
Copy link
Owner

kmamal commented Nov 20, 2023

Ah, I will have to do some more digging then.

@notchris
Copy link
Author

I just confirmed that the thread gets blocked on resize on mac, I did a setInterval with a counter and it stopped on resize. The problem may be harder to solve :X

@notchris
Copy link
Author

notchris commented Nov 20, 2023

The reply here claims that SDL_AddEventWatch(resizingEventWatcher, win);can create a watcher that wont block the main thread? https://stackoverflow.com/a/40693139/11287257

But then a following reply says:

`
If you are using a single thread, setting up an event watcher using SDL_AddEventWatch is not enough. This is because SDL_PumpEvents (which is called directly or indirectly by sdl) will not return until resizing is done, effectively blocking your thread.

To workaround this, you can setup a callback in your event watcher:
`
Which then details another possible workaround.

@kmamal
Copy link
Owner

kmamal commented Nov 20, 2023

Getting the event on another thread won't help if the main thread is stuck. I was looking more into the callback approach of SDL3: libsdl-org/SDL#8247 but I don't think this will play well with nodejs since we lose control of the main thread.

@notchris
Copy link
Author

notchris commented Nov 20, 2023

I see there is a patch on the thread, does that mean that SDL binary could be switched out with the one with the patch?

@kmamal
Copy link
Owner

kmamal commented Nov 20, 2023

Yeah we could patch sdl, but there are problems with that patch discussed later in the thread. I need to do some experimenting to see what is possible.

@kmamal
Copy link
Owner

kmamal commented Dec 5, 2023

I think the SDL_AddEventWatch approach can work. It will require a major rewrite of the C++ code but I've been meaning to do that for some time now. Please bear with me :D

@notchris
Copy link
Author

notchris commented Dec 5, 2023

@kmamal Thank you so much, I'll be patient :)

Let me know if I can help in anyway with parts of this project.

@clseibold
Copy link

clseibold commented Dec 5, 2023

This is a bug in SDL, not Windows. Every other program on Windows can render during resize, it's only SDL that has a problem with this.

@notchris
Copy link
Author

notchris commented Dec 8, 2023

@clseibold Yeah I assumed it was SDL specific because I get the same thing on macos.

@notchris
Copy link
Author

notchris commented Feb 1, 2024

Hey @kmamal! Let me know if I can attempt to contribute somehow! I've worked a bit with nodeapi bindings but probably need some direction / but would love to help get some small issues taken care of!

@kmamal
Copy link
Owner

kmamal commented Feb 1, 2024

Thanks for offering! The code itself is done, but I'm also trying to write as many tests as I can to make sure I didn't break anything during the rewrite. Shouldn't be much longer now :)

@kmamal
Copy link
Owner

kmamal commented Feb 6, 2024

@notchris check version 0.10.0 and let me know how it goes.

@notchris
Copy link
Author

notchris commented Feb 7, 2024

You're the best! @kmamal Going to check this out shortly

@notchris
Copy link
Author

notchris commented Feb 7, 2024

@kmamal

Nicely done, it's working on my end!

Screen.Recording.2024-02-07.at.6.05.01.PM.mov

@kmamal
Copy link
Owner

kmamal commented Feb 7, 2024

Perfect! Closing the issue then :)

@kmamal kmamal closed this as completed Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants