Make missing decoder non-failing.

Otherwise, if you try to open a random file in studio, it will crash.

PiperOrigin-RevId: 865372002
Change-Id: I96d3121b6de792daaff53155ea2436ac3f6668db
This commit is contained in:
Haroon Qureshi
2026-02-04 06:12:20 -08:00
committed by Copybara-Service
parent 1a9ca3239a
commit 1a0fe29c41
2 changed files with 10 additions and 3 deletions
+8 -1
View File
@@ -126,7 +126,14 @@ mjSpec* mj_parse(const char* filename, const char* content_type,
memcpy(resource->name, fullname.c_str(), sizeof(char) * (n + 1));
}
return mju_decodeResource(resource, content_type, vfs);
mjSpec* spec = mju_decodeResource(resource, content_type, vfs);
if (spec == nullptr) {
if (error) {
strncpy(error, "could not decode content", error_sz);
error[error_sz - 1] = '\0';
}
}
return spec;
}
// compile model