# WebBAR: EM_ASM heap indices from pointers use unsigned shifts (>>> 2 / >>> 3). With the WASM heap above # 2 GiB (large maps + several BARb AIs) `($0 >> 2) + n` wrapped to a huge end index, so build restrictions, # command descriptions and other word arrays read to the end of the heap (Nine Metal Islands + 3 AIs: # 61.8M garbage entries, 4.8 GB of strings, DataCloneError out of memory at 0:00). docs/map-batch/batch-3.md --- a/rts/Game/WebbarBrowser.h +++ b/rts/Game/WebbarBrowser.h @@ -149,7 +149,7 @@ } if (words[0] > 0) MAIN_THREAD_EM_ASM({ if (!Module['webbarCommandDescriptions']) return; - const words = HEAPU32.subarray($0 >> 2, ($0 >> 2) + $1); const units = []; let cursor = 1; + const words = HEAPU32.subarray($0 >>> 2, ($0 >>> 2) + $1); const units = []; let cursor = 1; for (let i = 0; i < words[0]; i++) { const unit = words[cursor++]; const count = words[cursor++]; const commands = []; for (let j = 0; j < count; j++) { @@ -169,7 +169,7 @@ const float economy[] = {team->res.metal, team->resStorage.metal, team->resPrevIncome.metal, team->resPrevExpense.metal, team->resPrevPull.metal, team->res.energy, team->resStorage.energy, team->resPrevIncome.energy, team->resPrevExpense.energy, team->resPrevPull.energy}; MAIN_THREAD_EM_ASM({ - if (Module['webbarEconomy']) Module['webbarEconomy']($0, HEAPF32.slice($1 >> 2, ($1 >> 2) + 10).buffer); + if (Module['webbarEconomy']) Module['webbarEconomy']($0, HEAPF32.slice($1 >>> 2, ($1 >>> 2) + 10).buffer); }, gs->frameNum, economy); const auto& units = WebbarUnits(); struct Record { uint32_t id; float progress; uint32_t queued; int32_t command; uint32_t target; float metal, energy; uint32_t transporter, cargo, selectionFlags; }; --- a/rts/Game/WebbarCatalog.h +++ b/rts/Game/WebbarCatalog.h @@ -27,9 +27,9 @@ }; MAIN_THREAD_EM_ASM({ if (!Module['webbarCatalog']) return; - const values = Array.from(HEAPF32.subarray($13 >> 2, ($13 >> 2) + 18)); + const values = Array.from(HEAPF32.subarray($13 >>> 2, ($13 >>> 2) + 18)); // Keep the host-call argument count below Emscripten's 16-argument limit. - const words = HEAPU32.subarray($14 >> 2, ($14 >> 2) + 13); + const words = HEAPU32.subarray($14 >>> 2, ($14 >>> 2) + 13); const yardmap = Array.from(HEAPU8.subarray(words[0], words[0] + words[1])); const nativeEconomy = ({version: 1, values, yardmap, xsize: words[2], zsize: words[3], onoffable: Boolean(words[4]), activateWhenBuilt: Boolean(words[5]), floatOnWater: Boolean(words[6]), --- a/rts/Game/WebbarEconomy.h +++ b/rts/Game/WebbarEconomy.h @@ -30,7 +30,7 @@ const uint32_t mask = ReadWebbarEnergyConversion(values); if (gu->spectating || !teamHandler.IsValidTeam(gu->myTeam)) return; MAIN_THREAD_EM_ASM({ - if (Module['webbarEnergyConversion']) Module['webbarEnergyConversion']($0, $1, $2, Array.from(HEAPF32.subarray($3 >> 2, ($3 >> 2) + 4))); + if (Module['webbarEnergyConversion']) Module['webbarEnergyConversion']($0, $1, $2, Array.from(HEAPF32.subarray($3 >>> 2, ($3 >>> 2) + 4))); }, gs->frameNum, gu->myTeam, mask, values); } --- a/rts/Game/WebbarPlacement.h +++ b/rts/Game/WebbarPlacement.h @@ -29,7 +29,7 @@ } MAIN_THREAD_EM_ASM({ if (!Module['webbarBuildRestrictions']) return; - const words = HEAPU32.subarray($0 >> 2, ($0 >> 2) + $1); + const words = HEAPU32.subarray($0 >>> 2, ($0 >>> 2) + $1); const entries = []; for (let i = 0; i < words.length; i += 2) entries.push([words[i], UTF8ToString(words[i + 1])]); Module['webbarBuildRestrictions']($2, $3, entries); --- a/rts/Game/WebbarReports.h +++ b/rts/Game/WebbarReports.h @@ -88,7 +88,7 @@ double(projMemPool.alloc_size()), double(projMemPool.freed_size()), double(weaponMemPool.alloc_size()), double(weaponMemPool.freed_size())}; MAIN_THREAD_EM_ASM({ if (!Module['webbarEngineMemory']) return; - const v = HEAPF64.subarray($0 >> 3, ($0 >> 3) + 14); + const v = HEAPF64.subarray($0 >>> 3, ($0 >>> 3) + 14); Module['webbarEngineMemory']({frame: v[0], heapBytes: v[1], mallinfo: {arena: v[2], uordblks: v[3], fordblks: v[4], keepcost: v[5]}, pools: {unit: {alloc: v[6], freed: v[7]}, feature: {alloc: v[8], freed: v[9]}, projectile: {alloc: v[10], freed: v[11]}, weapon: {alloc: v[12], freed: v[13]}}}); }, values); --- a/rts/Game/WebbarWeapons.h +++ b/rts/Game/WebbarWeapons.h @@ -122,7 +122,7 @@ const float width=original("beam_thickness_orig",v.thickness),core=original("beam_corethickness_orig",v.corethickness),flare=original("beam_laserflaresize_orig",v.laserflaresize),size=original("plasma_size_orig",d->size); const float values[]={v.color.x,v.color.y,v.color.z,v.color2.x,v.color2.y,v.color2.z,width,core,size,flare,v.beamdecay,float(d->beamLaserTTL),float(v.smokeTrail),v.smokeSize,v.smokeColor,float(v.smokeTime),float(v.smokePeriod),d->range,d->damages.damageAreaOfEffect}; MAIN_THREAD_EM_ASM({ - if(Module['webbarWeaponDef']) Module['webbarWeaponDef']({id:$0,name:UTF8ToString($1),type:UTF8ToString($2),impact:UTF8ToString($3),trail:UTF8ToString($4),model:UTF8ToString($5),preservedVisuals:!!$7,values:Array.from(HEAPF32.subarray($6>>2,($6>>2)+19))}); + if(Module['webbarWeaponDef']) Module['webbarWeaponDef']({id:$0,name:UTF8ToString($1),type:UTF8ToString($2),impact:UTF8ToString($3),trail:UTF8ToString($4),model:UTF8ToString($5),preservedVisuals:!!$7,values:Array.from(HEAPF32.subarray($6 >>> 2,($6 >>> 2)+19))}); },d->id,d->name.c_str(),d->type.c_str(),v.impactExpGenTag.c_str(),v.ptrailExpGenTag.c_str(),v.modelName.c_str(),values,(d->customParams.contains("beam_thickness_orig")||d->customParams.contains("plasma_size_orig"))); } pending.clear();