--- a/rts/Rendering/Models/3DModelVAO.cpp +++ b/rts/Rendering/Models/3DModelVAO.cpp @@ -169,6 +169,13 @@ void S3DModelVAO::UploadVBOs() { RECOIL_DETAILED_TRACY_ZONE; + #ifdef __EMSCRIPTEN__ + // Browser rendering uses its own model assets. Avoid redundant CPU buffers + // allocated by the headless GL fallback for unused engine GPU uploads. + vertUploadSize = vertData.size(); + indxUploadSize = indxData.size(); + return; + #endif static constexpr size_t MEM_STEP = 8 * 1024 * 1024; bool reinitVAO = (vao.GetIdRaw() == 0); --- a/rts/Rendering/Models/IModelParser.cpp +++ b/rts/Rendering/Models/IModelParser.cpp @@ -1,6 +1,11 @@ /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ #include +#ifdef __EMSCRIPTEN__ +#include +#include +#include +#endif #include #include @@ -280,6 +285,9 @@ S3DModel* CModelLoader::LoadModel(std::string name, bool preload) { ZoneScoped; +#ifdef __EMSCRIPTEN__ + try { +#endif // cannot happen except through SpawnProjectile if (name.empty()) return nullptr; @@ -313,6 +321,17 @@ Upload(model); return model; +#ifdef __EMSCRIPTEN__ + } catch (const std::bad_alloc&) { + // Lua catches foreign C++ exceptions without preserving the reason. A + // failed model also remains LOADING, so continuing can deadlock its waiters. + // Abort through the browser error callback, without allocating another string. + char message[768]; + std::snprintf(message, sizeof(message), "Model loading ran out of WebAssembly memory while loading \"%s\". Try a smaller map or fewer AI players.", name.c_str()); + MAIN_THREAD_EM_ASM({ abort(UTF8ToString($0 >>> 0)); }, message); + __builtin_trap(); + } +#endif } S3DModel* CModelLoader::GetCachedModel(std::string fullName)