From f1715e67bd52b685bc0bb6f8a560c15540a6c303 Mon Sep 17 00:00:00 2001 From: Matija Kecman Date: Wed, 18 Mar 2026 05:30:48 -0700 Subject: [PATCH] Fix studio web so that single file xml model can be loaded in a single-threaded wasm build model_holder.cc modified to disable multi-threaded compilation for WASM builds. index.html `animate()` function modified so the animation rendering loop executes asynchronously with async/await calls. These changes are sufficient to make xml files without references work (e.g., humanoid.xml), more work is needed to make the vfs work so multi-file models can load. PiperOrigin-RevId: 885537402 Change-Id: I3469cae48e7268073be334b99bf907c5ed8c27a7 --- src/experimental/platform/model_holder.cc | 4 ++++ src/experimental/studio/index.html | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/experimental/platform/model_holder.cc b/src/experimental/platform/model_holder.cc index 78bbc4cc..52652eaa 100644 --- a/src/experimental/platform/model_holder.cc +++ b/src/experimental/platform/model_holder.cc @@ -80,6 +80,10 @@ ModelHolder::~ModelHolder() { void ModelHolder::PostInit() { if (spec_ && !model_) { +#ifdef __EMSCRIPTEN__ + // Disable threaded compilation on WASM since pthreads are not available. + spec_->compiler.usethread = 0; +#endif model_ = mj_compile(spec_, &vfs_); if (!model_) { SetLoadError(mjs_getError(spec_)); diff --git a/src/experimental/studio/index.html b/src/experimental/studio/index.html index ee22448d..9a98df67 100644 --- a/src/experimental/studio/index.html +++ b/src/experimental/studio/index.html @@ -97,9 +97,9 @@ console.error('Failed to prefetch one or more assets.', error); }); }, - animate: () => { + animate: async () => { try { - Module.renderFrame(); + await Module.renderFrame(); } catch (error) { console.error('Update error:', error); }