Skip to content

Commit f1715e6

Browse files
okmatijacopybara-github
authored andcommitted
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
1 parent b0c48ba commit f1715e6

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/experimental/platform/model_holder.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ ModelHolder::~ModelHolder() {
8080

8181
void ModelHolder::PostInit() {
8282
if (spec_ && !model_) {
83+
#ifdef __EMSCRIPTEN__
84+
// Disable threaded compilation on WASM since pthreads are not available.
85+
spec_->compiler.usethread = 0;
86+
#endif
8387
model_ = mj_compile(spec_, &vfs_);
8488
if (!model_) {
8589
SetLoadError(mjs_getError(spec_));

src/experimental/studio/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@
9797
console.error('Failed to prefetch one or more assets.', error);
9898
});
9999
},
100-
animate: () => {
100+
animate: async () => {
101101
try {
102-
Module.renderFrame();
102+
await Module.renderFrame();
103103
} catch (error) {
104104
console.error('Update error:', error);
105105
}

0 commit comments

Comments
 (0)