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

It is not possible to call sapp_run multiple times #183

Closed
Oldes opened this issue Jul 9, 2019 · 5 comments
Closed

It is not possible to call sapp_run multiple times #183

Oldes opened this issue Jul 9, 2019 · 5 comments
Assignees

Comments

@Oldes
Copy link
Contributor

Oldes commented Jul 9, 2019

I would like to make a Sokol extension for Rebol language and I would like to be able to open Sokol's thread using sapp_run call multiple times. Not at once, but when I close the first one, to be able open a new one without restarting the host application. That is now not possible because of this assert:

sokol/sokol_app.h

Lines 4182 to 4183 in 5cf362a

_SOKOL_PRIVATE void _sapp_win32_init_dpi(void) {
SOKOL_ASSERT(0 == _sapp_win32_setprocessdpiaware);

Would you mind to replace this assert with just something like this?

_SOKOL_PRIVATE void _sapp_win32_init_dpi(void) {
    if (_sapp_win32_setprocessdpiaware != 0) return;

Or should I instead do some additional cleanup on my side, when the sapp_run call ends?

@floooh floooh self-assigned this Jul 9, 2019
@floooh
Copy link
Owner

floooh commented Jul 9, 2019

I haven't considered this use-case, but it's a good suggestion. It might be quite a few more places where this currently breaks though. The general idea is that every sokol API should properly clean up behind itself (in this case I think, _sapp_win32_setprocessdpiaware should be either be cleared at the end of sapp_run(), or all static variables should be cleared at start.

Some places basically assume that static variables are cleared by the compiler at startup, but that's no longer true when shutting down and starting the API, but not the process.

@pixelherodev
Copy link
Contributor

It's also not necessarily true if used in a dynamic library as I understand it - on some platforms (like the musl libc), dlclose() is actually a nop and a second dlopen just returns the same pointer from the first time. Not sure if this is also true on glibc, or Windows or anywhere else, but there's other situations where statics aren't going to be initialized to defaults.

@floooh
Copy link
Owner

floooh commented Feb 11, 2021

...better late then never... This is not quite the same as requested, but I've cleaned up the sokol headers a while ago so that the multiple shutdown/init cycles are possible. See this sample:

https://github.com/floooh/sokol-samples/blob/master/sapp/restart-sapp.c

@floooh floooh closed this as completed Feb 11, 2021
@Oldes
Copy link
Contributor Author

Oldes commented Feb 11, 2021

I've seen the sample... works well! Next question is... will sapp support multiple windows (something like in multiwindow-glfw.c)? Should I write a new wish for it? Not a big issue... just curious.. I know that it does not make much sense on some platforms.

@floooh
Copy link
Owner

floooh commented Feb 12, 2021

There's a fairly advanced pull request for multiwindow-support here:

#437

I haven't checked yet how much work remains there to be done, but eventually at one point in the future, this will be merged. Don't hold your breath though ;) But if you need multiwindow support, this PR is the best place to start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants