* Filament Error Handling Remediation and noexcept Cleanup - Replaced assert_invariant with FILAMENT_CHECK_PRECONDITION in Renderer::beginFrame for caller bugs. - Removed noexcept from Camera::setCustomProjection to allow precondition checks to throw. - Removed noexcept from Texture and InstanceBuffer methods using precondition checks. - Documented silent clamping in View::setBloomOptions. - Clarified comment in FrameGraphResources regarding preconditions. - Refined MaterialInstance::commit to split texture loop into check and update passes, preventing partial state changes on precondition failure. * backend: Propagate backend thread exceptions to the main thread. Introduce a mechanism to catch exceptions thrown on the backend thread and rethrow them on the main thread. This prevents deadlocks and allows the application to handle fatal backend failures gracefully. - Consolidate synchronization primitives in DriverBase. - Add mHasUnrecoverableError flag to interrupt blocked fence waits. - Optimize waitForFence to avoid extra atomic reads in common paths. - Propagate FenceStatus::ERROR across all backends. - CommandBufferQueue now stores a std::exception_ptr when the backend fails. - The backend enters a "zombie" state on failure, skipping further command execution but allowing clean shutdown. - Public APIs in Renderer and Engine now check for stored exceptions and rethrow them, documented with @throws. - Guarded by __EXCEPTIONS to ensure no overhead when exceptions are disabled. - Add unit test for fence interruption and document new APIs. BUGS=[407545700] * feat: harden backend exceptions and add hasUnrecoverableFailure API - Update Renderer::beginFrame() and Renderer::shouldRenderFrame() to return false early if an unrecoverable backend exception has been delivered to the main thread. - Document the new return behavior for beginFrame() and shouldRenderFrame() in Renderer.h. - Add Engine::hasUnrecoverableFailure() to the public API to allow apps to check for fatal errors without relying on exceptions. - Implement hasUnrecoverableFailure() in FEngine by delegating to CommandBufferQueue. - Expose Engine::hasUnrecoverableFailure() to Java bindings (Engine.java and JNI). - Expose Engine::hasUnrecoverableFailure() to JavaScript bindings (jsbindings.cpp). * java: propagate C++ Panics & exceptions to JAVA
Web Samples and Tutorials
This directory contains the web-based samples, tutorials, and the JavaScript wrapper for Filament.
Structure
-
examples/Contains the source for the WebGL tutorials, HTML samples, materials, and assets. These examples usefilament.jsandfilament.wasmto demonstrate various features of the engine. -
filament-js/Contains the JavaScript bindings for Filament, generated via Emscripten.
Building the Web Examples
To build the WebGL targets and compile all required materials and assets, you will need the Emscripten SDK installed and activated.
-
Activate Emscripten SDK: Make sure you have
EMSDKin your environment.cd path/to/emsdk ./emsdk activate latest source ./emsdk_env.sh -
Run the Build Script: From the root directory of the repository, execute the build script targeting WebGL:
./build.sh -p webgl releaseThis will:
- Compile the C++ engine to
filament.wasmandfilament.js. - Build all materials (
.matto.filamat) and process textures required by the examples. - Output everything into
out/cmake-webgl-release/examples/.
- Compile the C++ engine to
Running the Examples
Because of CORS restrictions and the need to serve WebAssembly files with the correct MIME type, you must serve the files via a local web server.
-
Install Python Requirements: The serve script dynamically renders Markdown tutorials on-the-fly using
mistletoe. It is highly recommended to use a Python virtual environment to install dependencies.python3 -m venv .venv source .venv/bin/activate pip install -r web/examples/requirements.txt -
Start the Server: From the root of the repository, run the
serve.pyscript:./web/examples/serve.py -
View the Examples: Open your browser and navigate to
http://localhost:8000. You will see an index page listing all the generated tutorials and samples.
Python Script: serve.py
The custom serve.py script in the web/examples/ directory performs the following:
- Automatically detects the built files in the
out/directory. - Generates a main entry
index.htmllisting all the available samples and tutorials. - Handles server-side rendering of
.mdtutorial files into HTML using an embedded template.
Porting a Web Sample to Official Docs (docs_src)
If you want your web sample or tutorial to appear on the official Filament documentation website via
mdbook, follow these steps:
-
Map the Built HTML: Add your generated
.htmlor.mdfile to the mapping indocs_src/build/duplicates.json. This tells the documentation build script to copy your sample into themdbookstructure."out/cmake-webgl-release/web/examples/examples/your_sample/your_sample.html": { "dest": "samples/web/your_sample.md" } -
Add to the Navigation Menu: Link your sample in the table of contents by adding it to
docs_src/src_mdbook/src/SUMMARY.mdunder the "Web Tutorials" or "Web Samples" section. -
Generate a Thumbnail Image: Add your sample's name to the
samplesarray indocs_src/build/snapshot_samples.py. Then, manually run this script (python3 snapshot_samples.py). It will launch a headless browser, wait for your scene to render, and snap a 100x100 preview image. -
Dynamic Asset Loading (Optional): When
mdbookserves your sample, the assets (.filamat, textures) are segregated into aweb/assets/directory.- For
<script src="...">or<img src="...">tags embedded in the HTML, the paths will be automatically rewritten bydocs_src/build/copy_web_docs.py. - However, if you load files dynamically within your JavaScript code (e.g., using
fetch()), you must prepend(window.FILAMENT_ASSET_DIR || '')to the file URL. - If you need
window.FILAMENT_ASSET_DIRto be properly populated, make sure to add logic todocs_src/build/copy_web_docs.pyto inject the proper path prefix for your sample.
- For