Skip to content

Fix native iOS view controller startup#8524

Open
yutaokuyama wants to merge 1 commit into
openframeworks:masterfrom
yutaokuyama:bugfix-ios-native-view-controller-startup
Open

Fix native iOS view controller startup#8524
yutaokuyama wants to merge 1 commit into
openframeworks:masterfrom
yutaokuyama:bugfix-ios-native-view-controller-startup

Conversation

@yutaokuyama

Copy link
Copy Markdown

Summary

Fixes openFrameworks apps embedded in a native UIKit view-controller hierarchy through a custom app delegate.

When startAppWithDelegate() is used with ofxiOSViewController or ofxiOSGLKViewController, the embedded app is removed from the main loop immediately after registration and does not receive setup(), update(), or draw() callbacks.

Cause

The view recreates the OF main loop and window, then registers the embedded app with:

ofRunApp(app);

This overload also calls ofRunMainLoop(). Since UIApplicationMain is already running, startAppWithDelegate() returns immediately through its bAppCreated guard.

Since #8148, returning from the window loop calls ofMainLoop::exit(), which removes the app and its listeners.

Fix

Register the app with the recreated window without starting the main loop again:

ofRunApp(window, std::static_pointer_cast<ofBaseApp>(app));

The same change is applied to the EAGL and GLK implementations.

The standard iOS startup path is unaffected because it does not enter this code path.

Testing

  • Reproduced on a physical iPhone with a minimal custom-app-delegate test using ofxiOSViewController. Before the fix, UIKit installs the view controller but no OF callbacks are received. After the fix, setup(), update(), and draw() all run.
  • Verified the GLK path with the same minimal setup on an iPhone 16 Pro (iOS 26.5.2) and an iOS 18.1 simulator.
  • Runtime testing used openFrameworks 0.12.1. The PR is based on current master, where the affected code paths are unchanged.
  • tvOS shares these view implementations but was not runtime-tested.

Custom app delegates start UIApplicationMain before an OF view controller installs its app. Calling the single-argument ofRunApp overload from view setup re-enters the iOS main loop; since openframeworks#8148, returning from that loop also runs exit() and removes the newly registered app and listeners.

Register the app against the recreated window with the window-specific overload so the active UIKit loop is not started or exited again.
@danoli3

danoli3 commented Jul 15, 2026

Copy link
Copy Markdown
Member

Thank you! Will test

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

Successfully merging this pull request may close these issues.

2 participants