From c420a6e1ca3abbaec841171e6fd22a6e30408502 Mon Sep 17 00:00:00 2001 From: Matija Kecman Date: Tue, 17 Mar 2026 03:31:19 -0700 Subject: [PATCH] Fix resizing the window when running single threaded This was affecting code running in the browser using WASM PiperOrigin-RevId: 884921901 Change-Id: I13e634452275927f58a63179cdf140780852be2f --- .../filament/filament/filament_context.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/experimental/filament/filament/filament_context.cc b/src/experimental/filament/filament/filament_context.cc index 49549992..6d7f9a29 100644 --- a/src/experimental/filament/filament/filament_context.cc +++ b/src/experimental/filament/filament/filament_context.cc @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -143,7 +144,9 @@ void FilamentContext::Render(const mjrRect& viewport, const mjvScene* scene, if (scene_swap_chain_target_ == kWindowSwapChain && (viewport.width != window_width_ || viewport.height != window_height_)) { if (window_width_ != 0 && window_height_ != 0) { - engine_->flushAndWait(); + if constexpr (UTILS_HAS_THREADING) { + engine_->flushAndWait(); + } engine_->destroy(window_swap_chain_); window_swap_chain_ = engine_->createSwapChain(config_.native_window); } @@ -171,10 +174,10 @@ void FilamentContext::Render(const mjrRect& viewport, const mjvScene* scene, // Render the frame if we're not rendering to a texture. if (scene_swap_chain_target_ == kWindowSwapChain) { - #ifndef __EMSCRIPTEN__ + if constexpr (UTILS_HAS_THREADING) { // Wait until previous frame is completed before requesting a new frame. engine_->flushAndWait(); - #endif + } if (renderer_->beginFrame(window_swap_chain_)) { filament::View* fview = scene_view_->PrepareRenderView(last_render_mode_); @@ -190,9 +193,9 @@ void FilamentContext::Render(const mjrRect& viewport, const mjvScene* scene, renderer_->endFrame(); } - #ifdef __EMSCRIPTEN__ + if constexpr (!UTILS_HAS_THREADING) { engine_->execute(); - #endif + } } } @@ -342,8 +345,10 @@ void FilamentContext::ReadPixels(mjrRect viewport, unsigned char* rgb, } if (rgb || depth) { - // Wait for rendering and copy back to buffer to complete. - engine_->flushAndWait(); + if constexpr (UTILS_HAS_THREADING) { + // Wait for rendering to copy back to buffer to complete. + engine_->flushAndWait(); + } } }