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

Background/foreground app events on iOS do not work when running under the event loop #11627

Open
frenzibyte opened this issue Dec 10, 2024 · 4 comments
Labels
waiting Waiting on user response
Milestone

Comments

@frenzibyte
Copy link
Contributor

frenzibyte commented Dec 10, 2024

Our application generally powers up as follows:

  • Call SDL_RunApp with a main function
  • Within main function, initialise everything and call SDL_SetiOSAnimationCallback to hand off the game loop to the display link initialised by SDL for correct frame pacing.
  • Return from the main function.

SDL seems to be aware of this kind of logic already:

// exit, passing the return status from the user's application
/* We don't actually exit to support applications that do setup in their
* main function and then allow the Cocoa event loop to run. */
// exit(exit_status);

But going a few lines back, it's doing this right after coming back from our main function:

SDL_SetiOSEventPump(false);

Which in turn removes the LifecycleObserver and not listen to any notification regarding the state of the app (i.e. applicationWillResignActive/applicationDidBecomeActive), causing the app to not receive such events.

@slouken
Copy link
Collaborator

slouken commented Dec 10, 2024

I'm not sure what the right solution is here. Feel free to create a PR with something that works for you!

@slouken slouken added the waiting Waiting on user response label Dec 10, 2024
@frenzibyte
Copy link
Contributor Author

I will have to begin by asking why iOS event pumps are disabled after the main function in the first place, and/or why the lifecycle observer is using that as a condition on whether to run.

This is all as well as why the lifecycle observer apparently has a fallback condition wherein if the app was running using SDL's main callbacks then the lifecycle observer is attached regardless of iOS's event pump state.

@frenzibyte
Copy link
Contributor Author

After further consideration, given our specific use case of SDL on iOS here, I think it may be a better option for us to roll out our own application delegate class and use SDL_SetMainReady instead (albeit we will have to copy certain handlings). This can be closed if it's on the verge of being by-design.

@icculus
Copy link
Collaborator

icculus commented Dec 11, 2024

I'm sort of assuming this is a bug in SDL, but I don't know the details of this code at all.

I assume this code path is trying to make it so SDL_PumpEvents does nothing because it would run the CFRunLoop, but setting an animation callback means we basically live in a runloop and don't have to (or shouldn't) manually run it...but I don't know why we turn off the observer.

Also: the iOS-specific main callbacks codepath literally calls SDL_PumpEvents, so it must be safe to do so even with an animation callback...?

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

No branches or pull requests

3 participants