-
Notifications
You must be signed in to change notification settings - Fork 154
Factor out shared parts of the playground #1593
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR factors the duplicated Playground engine initialization logic across platforms into a shared AppContext utility and updates all platform frontends to use it, while also bumping the NativeEngine protocol version. The intent is to centralize device/runtime/plugin setup and script loading so that all Playground variants behave consistently and are easier to maintain.
Changes:
- Introduces
Apps/Playground/Shared/AppContextto encapsulateDevice,DeviceUpdate,AppRuntime, polyfills, plugins, and common script loading, with hooks for platform-specific initialization and logging. - Refactors platform-specific Playground entrypoints (iOS, macOS, visionOS, Android, Win32, UWP, X11) to construct and drive
AppContextinstead of rolling their own setup, and adjusts script-loading logic accordingly. - Bumps
NativeEngine’sPROTOCOL_VERSIONconstant from 9 to 10 and updates the Win32 CI pipeline to disable the Chakra JIT debugger so JS exceptions don’t hang tests.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
Plugins/NativeEngine/Source/NativeEngine.cpp |
Bumps the static PROTOCOL_VERSION exposed to JS to 10 to reflect a protocol change. |
Apps/Playground/visionOS/LibNativeBridge.mm |
Replaces inline Babylon initialization with an AppContext instance that manages device, runtime, and script loading on visionOS. |
Apps/Playground/macOS/ViewController.mm |
Switches macOS Playground to use a global AppContext for rendering and input, and reimplements script selection (default vs custom scripts) via ScriptLoader() on the context. |
Apps/Playground/iOS/LibNativeBridge.mm |
Refactors iOS Playground initialization to construct AppContext plus a platform-specific AdditionalInitCallback for XR/tracing, delegating touch input and rendering to the shared context. |
Apps/Playground/X11/App.cpp |
Moves Babylon initialization and per-frame rendering to a shared AppContext instance, rewires mouse input through AppContext::Input(), and adjusts script-loading behavior based on CLI arguments. |
Apps/Playground/Win32/App.cpp |
Replaces manual device/runtime/polyfill/plugin setup with AppContext, routes window lifecycle and pointer/mouse input through its accessors, and simplifies script selection using GetCommandLineArguments(). |
Apps/Playground/UWP/App.h |
Collapses the separate device, runtime, canvas, and native input members into a single std::optional<AppContext> for UWP. |
Apps/Playground/UWP/App.cpp |
Updates the UWP app lifecycle and pointer handlers to use m_appContext for rendering, suspension/resume, resizing, and script loading, preserving the file-based script-runner behavior. |
Apps/Playground/Shared/AppContext.h |
Declares the AppContext class, its public accessors for core engine components, and callbacks for debug logging and platform-specific initialization. |
Apps/Playground/Shared/AppContext.cpp |
Implements AppContext: enabling debug/perf tracing, creating the graphics device + update loop, wiring polyfills and plugins (including TestUtils), configuring the unhandled exception handler, and preloading core Babylon scripts. |
Apps/Playground/CMakeLists.txt |
Adds Shared/AppContext.{cpp,h} to the Playground sources, adjusts include paths, links NativeCamera at the target level, and wires the shared code into all platform variants. |
Apps/Playground/Android/BabylonNative/src/main/cpp/BabylonNativeJNI.cpp |
Refactors the Android JNI bridge to create and use a global AppContext plus Android-specific XR initialization, routing resize, render, and touch events through it, and delegating script evaluation to ScriptLoader(). |
.github/jobs/win32.yml |
Adds a step on Win32 CI to disable the Chakra JIT debugger via registry so uncaught JS exceptions fail tests cleanly instead of hanging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Babylon::AppRuntime::Options options{}; | ||
|
|
||
| options.EnableDebugger = true; | ||
|
|
||
| options.UnhandledExceptionHandler = [debugLog](const Napi::Error& error) { | ||
| std::ostringstream ss{}; | ||
| ss << "[Uncaught Error] " << Napi::GetErrorString(error); | ||
|
|
||
| debugLog(ss.str().data()); | ||
|
|
||
| std::quick_exit(1); | ||
| }; |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Centralizing the UnhandledExceptionHandler here to always call std::quick_exit(1) changes error-handling semantics for all playground platforms and bypasses normal C++ teardown. In particular, this now skips AppContext's destructor (and other RAII cleanup), and for Win32 it no longer routes unhandled JavaScript exceptions through TestUtils::errorCode / the window message loop (Win32/App.cpp:335), which previously allowed tests to observe a specific exit code. Consider either (a) exposing the handler as a parameter so each platform can preserve its prior behavior, or (b) at least avoiding quick_exit in favor of returning control so existing shutdown/error reporting paths can run.
No description provided.