From b34ebaca05e7a2c13c7e3626eff18e2a6f028ea8 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 8 Oct 2026 23:53:10 +0000 Subject: [PATCH 1/3] togles: fix the program link-failure path that crashed WebGL When a GLSL program failed to link, CGLMShaderPair::SetProgramPair called glGetShaderiv(GL_INFO_LOG_LENGTH) on the *program* id. Emscripten serves that through getShaderInfoLog(GL.shaders[id]), so WebGL received something that is not a shader and threw - the iPhone crash "Argument 1 ('shader') to WebGL2RenderingContext.getShaderInfoLog must be an instance of WebGLShader". The program info log is now read with glGetProgramInfoLog only, and both link and compile failures log one bounded line with the shader names and the driver's message instead of dumping both full shader sources through Msg. Programs failing to link on iPhone also fits the menu text drawing as boxes; the new lines land in the diagnostics' error list so the driver's reason is visible on the next run. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Qy5DKdwTqGQqScWvJyNcft --- togles/linuxwin/cglmprogram.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/togles/linuxwin/cglmprogram.cpp b/togles/linuxwin/cglmprogram.cpp index 4c9669c27e..81bc912741 100644 --- a/togles/linuxwin/cglmprogram.cpp +++ b/togles/linuxwin/cglmprogram.cpp @@ -360,9 +360,11 @@ void CGLMProgram::Compile( EGLMProgramLang lang ) gGL->glGetShaderiv(glslDesc->m_object.glsl , GL_INFO_LOG_LENGTH, &maxLength); GLchar log[4096]; + log[0] = 0; gGL->glGetShaderInfoLog( glslDesc->m_object.glsl, sizeof(log), &maxLength, log ); - Msg("shader compile log: %s\n", log); - Msg("Shader %d source is:\n===============\n%s\nn===============\n", glslDesc->m_object.glsl, section); + log[sizeof(log) - 1] = 0; + Msg( "[Render360 GL] shader compile failed: %s %s :: %.900s\n", + glslStage == GL_FRAGMENT_SHADER ? "ps" : "vs", m_shaderName[0] ? m_shaderName : "?", log ); } #if 0 //GLM_FREE_SHADER_TEXT @@ -990,16 +992,17 @@ bool CGLMShaderPair::SetProgramPair( CGLMProgram *vp, CGLMProgram *fp ) gGL->glGetProgramiv(m_program, GL_LINK_STATUS, &isLinked); if(isLinked == GL_FALSE) { - GLint maxLength = 0; - gGL->glGetShaderiv(m_program, GL_INFO_LOG_LENGTH, &maxLength); - + // This used to ask glGetShaderiv about the *program* id. Under WebGL + // that hands getShaderInfoLog a non-shader and throws, which is the + // "must be an instance of WebGLShader" crash seen on iPhone. GLchar log[4096]; + log[0] = 0; + GLint maxLength = 0; gGL->glGetProgramInfoLog( m_program, sizeof(log), &maxLength, log ); - if( maxLength ) - { - Msg("vp: \n%s\nfp: \n%s\n", vp->m_text, fp->m_text ); - Msg("shader %d link log: %s\n", m_program, log); - } + log[sizeof(log) - 1] = 0; + // One bounded line: full shader dumps are tens of KB per failure. + Msg( "[Render360 GL] program link failed: vs=%s ps=%s :: %.900s\n", + vp->m_shaderName[0] ? vp->m_shaderName : "?", fp->m_shaderName[0] ? fp->m_shaderName : "?", log ); } m_bCheckLinkStatus = true; From c3669fa28271085c8034a0d90380653e1c960543 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 9 Oct 2026 01:28:14 +0000 Subject: [PATCH 2/3] iphone: New Game chapters, clean text, no audio buzz, pad drives menus New Game: the dialog lists chapters with FindFirst("cfg/chapter*.cfg"). Directory listings come from the main thread's shared FS, which only had gameinfo and VPK placeholders; the user's loose cfg/scripts/resource/maps files were linked on the Source worker only. The chapter list was empty and "Start new game" had nothing to start. post.js now adds zero-byte names for those loose files too; opens and stats are still intercepted by filesystem_stdio and served from the real File. Text: the font page reaches the screen with alpha read as opaque, so each glyph drew on a black box. Glyph coverage is already in RGB on the web build, so the procedural font materials now blend additively there; the box disappears whether or not alpha survives. Bitmap fonts keep alpha blending. Audio: the AudioWorklet kept reading the ring even when the engine had not painted new samples, replaying stale contents - the buzz. The engine now publishes the sample time it has written (m_paintedEnd) and the reader never plays past it, outputting silence instead. snd_mixahead 0.25 gives slower phone frames more headroom inside the 0.37 s ring. Rendering: mat_bumpmap/mat_specular stay on; turning them off made Portal materials request a $bumpmap texture that was never loaded (red console errors), and the crash they were meant to avoid was the togles link-log bug. Controller: works on the menus. Menu mode (background map, pause menu): stick sends arrow keys with auto-repeat, A/Start/X Enter, B/Back Escape, LB/RB left/right. Game mode once a real map loads; Pause toggles between the two. It stays visible on the menus. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Qy5DKdwTqGQqScWvJyNcft --- emscripten/assets/r360-controller.js | 84 ++++++++++++++++++++++++---- emscripten/post.js | 20 ++++++- emscripten/pre.js | 36 +++++++----- engine/audio/snd_dev_sdl.cpp | 14 ++++- vguimatsurface/FontTextureCache.cpp | 10 ++++ 5 files changed, 136 insertions(+), 28 deletions(-) diff --git a/emscripten/assets/r360-controller.js b/emscripten/assets/r360-controller.js index 9c706c76e0..b8c2fec578 100644 --- a/emscripten/assets/r360-controller.js +++ b/emscripten/assets/r360-controller.js @@ -26,8 +26,20 @@ TAB: { key: 'Tab', code: 'Tab', keyCode: 9 }, F6: { key: 'F6', code: 'F6', keyCode: 117 }, F9: { key: 'F9', code: 'F9', keyCode: 120 }, + UP: { key: 'ArrowUp', code: 'ArrowUp', keyCode: 38 }, + DOWN: { key: 'ArrowDown', code: 'ArrowDown', keyCode: 40 }, + LEFT: { key: 'ArrowLeft', code: 'ArrowLeft', keyCode: 37 }, + RIGHT: { key: 'ArrowRight', code: 'ArrowRight', keyCode: 39 }, }; + // Two mappings. "game" drives Portal; "menu" drives Source's menus and + // dialogs: the stick moves the selection, A/Start accept, B/Pause go back. + // The mode follows the game: menu on the background map and while paused, + // game once a real map loads. + const MENU_KEYS = { a: 'ENTER', start: 'ENTER', x: 'ENTER', b: 'ESC', y: null, back: 'ESC', + lb: 'LEFT', rb: 'RIGHT', lt: null, rt: null }; + let mode = 'menu'; + // Portal's default bindings. Geometry is measured one-to-one from the // reference pad (iPhone 11 landscape, 896x350 CSS px below Safari's bar): // x/y are the top-left corner as fractions of the page, w/h in CSS px. @@ -63,8 +75,6 @@ /* Face buttons are short pills (50x41), not circles or ellipses. */ #r360c button.r360c-face { border-radius: 999px; } #r360c button.r360c-down { transform: scale(.94); background: rgba(var(--bd), .7); border-color: rgba(255,255,255,.55); } - #r360c.r360c-menu button:not([data-id="pause"]) { display: none; } - #r360c.r360c-menu #r360c-stick { display: none; } .r360c-gray { --bg: 27,28,32; --bd: 60,62,68; } .r360c-amber { --bg: 52,40,22; --bd: 120,94,48; } .r360c-navy { --bg: 18,26,40; --bd: 44,60,86; } @@ -161,22 +171,37 @@ try { button.setPointerCapture(pointer); } catch (_) {} button.classList.add('r360c-down'); if (spec.menuToggle) { + // Escape opens the pause menu in a level and backs out of menus. keyEvent('keydown', spec.key); keyEvent('keyup', spec.key); releaseAll(); - root.classList.toggle('r360c-menu'); - } else if (spec.key) { + if (inMap) setMode(mode === 'game' ? 'menu' : 'game'); + return; + } + if (mode === 'menu') { + const name = MENU_KEYS[spec.id]; + if (name) { + keyEvent('keydown', name); + keyEvent('keyup', name); + // Backing out of the pause menu returns to the game. + if (name === 'ESC' && inMap) setMode('game'); + } + return; + } + if (spec.key) { press(spec.key); } else if (spec.mouse !== undefined) { mouseEvent('mousedown', spec.mouse); } + button.dataset.held = '1'; }; const up = (event) => { if (pointer === null || event.pointerId !== pointer) return; event.preventDefault(); pointer = null; button.classList.remove('r360c-down'); - if (spec.menuToggle) return; + if (button.dataset.held !== '1') return; + delete button.dataset.held; if (spec.key) release(spec.key); else if (spec.mouse !== undefined) mouseEvent('mouseup', spec.mouse); }; @@ -198,7 +223,32 @@ let stickPointer = null; const stickKeys = new Set(); + // Menu mode: one arrow press per direction change, then auto-repeat while + // the stick is held, like a console pad in a list. + let menuDir = null; + let menuTimer = 0; + function menuStep(dir) { + if (dir === menuDir) return; + menuDir = dir; + clearTimeout(menuTimer); + if (!dir) return; + const tap = () => { keyEvent('keydown', dir); keyEvent('keyup', dir); }; + tap(); + const repeat = () => { if (menuDir !== dir) return; tap(); menuTimer = setTimeout(repeat, 140); }; + menuTimer = setTimeout(repeat, 380); + } + function setStickKeys(next) { + if (mode === 'menu') { + let dir = null; + if (next.has('W')) dir = 'UP'; + else if (next.has('S')) dir = 'DOWN'; + else if (next.has('A')) dir = 'LEFT'; + else if (next.has('D')) dir = 'RIGHT'; + menuStep(dir); + return; + } + menuStep(null); for (const name of stickKeys) if (!next.has(name)) { stickKeys.delete(name); release(name); } for (const name of next) if (!stickKeys.has(name)) { stickKeys.add(name); press(name); } } @@ -347,15 +397,26 @@ } // ------------------------------------------------------------------ state - // Shown in a real map, hidden on the menu background map so menu taps reach - // the game. The in-game menu can also show or hide it. + // Visible by default on touch screens, on the menus too, so the menus can + // be driven with the stick and A. The ••• menu can hide or show it. let wanted = null; // null = automatic, true/false = player's choice let inMap = false; + function setMode(next) { + if (mode === next) return; + releaseAll(); + menuStep(null); + for (const name of Array.from(stickKeys)) { stickKeys.delete(name); } + mode = next; + root.dataset.mode = mode; + const label = stick.querySelector('.r360c-label'); + if (label) label.textContent = mode === 'menu' ? 'Select' : 'Move'; + } + function apply() { - const on = wanted === null ? inMap : wanted; + const on = wanted === null ? true : wanted; root.classList.toggle('r360c-on', on); - if (!on) { releaseAll(); root.classList.remove('r360c-menu'); } + if (!on) { releaseAll(); menuStep(null); } const toggle = document.getElementById('r360-controller-row'); if (toggle) toggle.textContent = on ? 'Hide controller' : 'Show controller'; } @@ -372,11 +433,14 @@ /\bloaded\s+([A-Za-z0-9_]+)\.data\b/.exec(line); if (!match) return; inMap = !/^background/i.test(match[1]); - root.classList.remove('r360c-menu'); + setMode(inMap ? 'game' : 'menu'); apply(); }; function mount() { + root.dataset.mode = mode; + const label = stick.querySelector('.r360c-label'); + if (label) label.textContent = mode === 'menu' ? 'Select' : 'Move'; document.body.appendChild(root); layout(); apply(); diff --git a/emscripten/post.js b/emscripten/post.js index 349b79180b..32a4bd002f 100644 --- a/emscripten/post.js +++ b/emscripten/post.js @@ -105,6 +105,7 @@ let count = 0 let bytes = 0 let vpkPlaceholders = 0 + let loosePlaceholders = 0 let hasPortalGameInfo = false for(const item of Array.isArray(files) ? files : []) { const path = normalize(item && item.path) @@ -130,6 +131,23 @@ FS.writeFile(fullPath, new Uint8Array(0)) } vpkPlaceholders++ + continue + } + + // Loose retail files (cfg/, scripts/, resource/, maps/) need names + // in this shared namespace too: Source finds them by *listing* + // directories (the New Game dialog enumerates cfg/chapter*.cfg), + // and listings come from here. Opens and stats are intercepted by + // filesystem_stdio and served from the real File, so a zero-byte + // name costs nothing and never shadows the content. + if(/^(?:portal|hl2|platform)\/(?:cfg|scripts|resource|maps)\//i.test(path)) { + ensureParent(fullPath) + try { + FS.lookupPath(fullPath, { follow: false }) + } catch(_) { + FS.writeFile(fullPath, new Uint8Array(0)) + } + loosePlaceholders++ } } @@ -147,7 +165,7 @@ Module.render360Phase3StartupMemfsBytes = bytes Module.render360Phase3StartupMemfsFiles = count Module.render360Phase3VpkPlaceholders = vpkPlaceholders - Module.print?.(`[Render360 Phase 3] staged ${count} startup metadata files (${bytes} bytes) plus ${vpkPlaceholders} zero-byte VPK namespace placeholders; retail VPK payload remains browser-backed`) + Module.print?.(`[Render360 Phase 3] staged ${count} startup metadata files (${bytes} bytes) plus ${vpkPlaceholders} zero-byte VPK and ${loosePlaceholders} loose-file namespace placeholders; retail payload remains browser-backed`) try { globalThis.render360SetPhase?.(`phase3-startup-metadata-ready:vpk=${vpkPlaceholders}`) } catch(_) {} } diff --git a/emscripten/pre.js b/emscripten/pre.js index 859cd60cdc..bcf517eb49 100644 --- a/emscripten/pre.js +++ b/emscripten/pre.js @@ -295,7 +295,10 @@ Module['arguments'].push( // itself whenever it believes the window is in the background. '+snd_mute_losefocus', '0', // Full scale is harsh on a phone speaker; still adjustable in Options. - '+volume', '0.7' + '+volume', '0.7', + // Paint further ahead than the desktop 0.1 s: phone frames are slower, + // and the ring holds 0.37 s. + '+snd_mixahead', '0.25' ) // A phone has no keyboard and iOS has never shipped Pointer Lock, so the @@ -316,14 +319,10 @@ if(render360IsWindow) { // see, and textures are the largest thing a map load adds to both the // Wasm heap and GPU memory, which is where iOS kills the page. Module['arguments'].push('+mat_picmip', '2') - // Graphics memory is the next limit after the Wasm heap: the first - // iPhone run that reached the menu lost its WebGL context while the - // engine was caching materials. Normal maps double the texture memory - // of almost every Portal surface, specular cubemaps and shadow render - // targets add more, and none of it is worth a lost context on a phone. + // Cheaper rendering features for a phone GPU. Bump maps and specular + // stay on: turning them off makes Portal's materials ask for a + // $bumpmap texture that is not loaded (console errors). Module['arguments'].push( - '+mat_bumpmap', '0', - '+mat_specular', '0', '+r_shadowrendertotexture', '0', '+r_flashlightdepthtexture', '0', '+r_waterforceexpensive', '0', @@ -925,6 +924,7 @@ if(render360IsWindow) { this.i16 = new Int16Array(d.sab); this.i32 = new Int32Array(d.sab); this.frac = 0; + this.abs = 0; }; } process(inputs, outputs) { @@ -938,11 +938,16 @@ if(render360IsWindow) { const frames = c.bytes >> 2; const base = c.buf >> 1; const step = c.rate / sampleRate; - let pos = Atomics.load(this.i32, c.readIdx); - if (pos < 0 || pos >= c.bytes) pos = 0; - let frame = pos >> 2; + // Absolute sample time read so far (the engine's "soundtime") and + // the time the engine has finished writing up to. Never play past + // what was written: replaying stale ring contents is a buzz. + const painted = c.paintedIdx >= 0 ? Atomics.load(this.i32, c.paintedIdx) : 0x7fffffff; + if (painted < this.abs - frames) this.abs = painted; // engine restarted its clock + let frame = this.abs % frames; let frac = this.frac; - for (let i = 0; i < L.length; i++) { + let i = 0; + for (; i < L.length; i++) { + if (this.abs + 1 >= painted) break; const next = frame + 1 === frames ? 0 : frame + 1; const a = base + frame * 2, b = base + next * 2; const l0 = this.i16[a], r0 = this.i16[a + 1]; @@ -952,7 +957,9 @@ if(render360IsWindow) { const whole = frac | 0; frac -= whole; frame = (frame + whole) % frames; + this.abs += whole; } + for (; i < L.length; i++) { L[i] = 0; if (R !== L) R[i] = 0; } this.frac = frac; Atomics.store(this.i32, c.readIdx, frame << 2); return true; @@ -977,10 +984,11 @@ if(render360IsWindow) { else resumeAudio() }) - Module.render360AudioStart = (buf, bytes, readPosPtr, pausePtr, rate) => { + Module.render360AudioStart = (buf, bytes, readPosPtr, pausePtr, rate, paintedPtr) => { try { if(navigator.audioSession) navigator.audioSession.type = 'playback' } catch(_) {} const sab = (typeof wasmMemory !== 'undefined' && wasmMemory) ? wasmMemory.buffer : HEAP8.buffer - const config = { sab, buf, bytes, readIdx: readPosPtr >> 2, pauseIdx: pausePtr >> 2, rate } + const config = { sab, buf, bytes, readIdx: readPosPtr >> 2, pauseIdx: pausePtr >> 2, rate, + paintedIdx: paintedPtr ? paintedPtr >> 2 : -1 } const AC = window.AudioContext || window.webkitAudioContext if(!AC) { Module.printErr?.('[Render360 audio] Web Audio unavailable'); return } let ctx diff --git a/engine/audio/snd_dev_sdl.cpp b/engine/audio/snd_dev_sdl.cpp index 4bc9d4a571..94f1ae0f0e 100644 --- a/engine/audio/snd_dev_sdl.cpp +++ b/engine/audio/snd_dev_sdl.cpp @@ -106,6 +106,7 @@ class CAudioDeviceSDLAudio : public CAudioDeviceBase int m_pauseCount; int m_readPos; int m_partialWrite; + int m_paintedEnd; // web: last sample time written into the ring // Memory for the wave data uint8_t *m_pBuffer; @@ -169,6 +170,7 @@ bool CAudioDeviceSDLAudio::Init( void ) m_pBuffer = NULL; m_readPos = 0; m_partialWrite = 0; + m_paintedEnd = 0; m_devId = 0; OpenWaveOut(); @@ -241,11 +243,11 @@ void CAudioDeviceSDLAudio::OpenWaveOut( void ) // same 'callHandler' message Emscripten's own proxying understands. EM_ASM({ if (typeof ENVIRONMENT_IS_PTHREAD !== 'undefined' && ENVIRONMENT_IS_PTHREAD) { - postMessage({ cmd: 'callHandler', handler: 'render360AudioStart', args: [$0, $1, $2, $3, $4] }); + postMessage({ cmd: 'callHandler', handler: 'render360AudioStart', args: [$0, $1, $2, $3, $4, $5] }); } else if (Module.render360AudioStart) { - Module.render360AudioStart($0, $1, $2, $3, $4); + Module.render360AudioStart($0, $1, $2, $3, $4, $5); } - }, m_pBuffer, WAV_BUFFER_SIZE * WAV_BUFFERS, &m_readPos, &m_pauseCount, SOUND_DMA_SPEED); + }, m_pBuffer, WAV_BUFFER_SIZE * WAV_BUFFERS, &m_readPos, &m_pauseCount, SOUND_DMA_SPEED, &m_paintedEnd); DevMsg( "Render360: web audio ring %d bytes at %d Hz\n", WAV_BUFFER_SIZE * WAV_BUFFERS, SOUND_DMA_SPEED ); return; #endif @@ -597,6 +599,12 @@ void CAudioDeviceSDLAudio::TransferSamples( int end ) if ( m_pBuffer ) { S_TransferStereo16( m_pBuffer, PAINTBUFFER, lpaintedtime, endtime ); +#ifdef __EMSCRIPTEN__ + // Published after the samples are in the ring: the web reader never + // plays past this point, so a slow frame is a short gap instead of + // the stale ring looping (a buzz). + __atomic_store_n( &m_paintedEnd, endtime, __ATOMIC_RELEASE ); +#endif } } diff --git a/vguimatsurface/FontTextureCache.cpp b/vguimatsurface/FontTextureCache.cpp index c0d62bfaac..9921bad5cd 100644 --- a/vguimatsurface/FontTextureCache.cpp +++ b/vguimatsurface/FontTextureCache.cpp @@ -363,6 +363,16 @@ void CFontTextureCache::CreateFontMaterials( Page_t &page, ITexture *pFontTextur pVMTKeyValues->SetInt( "$ignorez", 1 ); pVMTKeyValues->SetInt( "$no_fullbright", 1 ); pVMTKeyValues->SetInt( "$translucent", 1 ); +#ifdef __EMSCRIPTEN__ + // On iPhone WebGL the font page's alpha reads as opaque, so normal alpha + // blending paints each glyph's whole cell (the black box behind every + // letter). Glyph coverage is also in RGB on this build (linuxfont.cpp), so + // additive blending draws exactly the letter shape either way. Text in + // Source's UI is light on dark, which additive handles. Bitmap fonts come + // from image files whose shape lives only in alpha, so they keep blending. + if ( !bitmapFont ) + pVMTKeyValues->SetInt( "$additive", 1 ); +#endif pVMTKeyValues->SetString( "$basetexture", pFontTexture->GetName() ); IMaterial *pMaterial = g_pMaterialSystem->CreateMaterial( "__fontpage", pVMTKeyValues ); pMaterial->Refresh(); From d04fe7198739717c0cc41c7f5b4683a95bf584e2 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 9 Oct 2026 05:55:10 +0000 Subject: [PATCH 3/3] iphone: survive level load (16 MB engine stack), named crash stacks, pad fades New Game now reaches testchmb_a_00, but ~75 s into loading the level the engine thread died with an out-of-bounds access inside the main module's low-numbered runtime functions (allocator range) - the signature of heap memory overwritten earlier. Level load is where Source recurses deepest (BSP and physics collision building), and under PROXY_TO_PTHREAD the engine thread gets STACK_SIZE, which was 4 MB against Linux's 8 MB. A silent stack overflow into the heap fits. STACK_SIZE is now 16 MB. To make the next crash, if any, conclusive: modules and the main module are linked with --profiling-funcs so Safari's Wasm stacks carry function names (the CI ban on it is lifted while crashes are traced), and the worker crash stack is kept whole (40 frames, 3000 chars) instead of being cut at 300 characters. Controller: fades to 16% opacity after 4 s without a touch and comes back on any touch; never fades while a control is held. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Qy5DKdwTqGQqScWvJyNcft --- .github/workflows/build.yml | 6 ++---- emscripten/assets/r360-controller.js | 21 +++++++++++++++++++++ emscripten/build.sh | 4 ++-- emscripten/pre.js | 12 ++++++++---- wscript | 3 +++ 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9aa5dce7df..e8bcff7a51 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,10 +62,8 @@ jobs: echo 'Render360 Portal: mimalloc returned to the iPhone release profile.' >&2 exit 1 fi - if grep -q -- '--profiling-funcs' emscripten/build.sh; then - echo 'Render360 Portal: profiling function names returned to the iPhone release build.' >&2 - exit 1 - fi + # --profiling-funcs is deliberately on while iPhone crashes are being + # traced: it is the only way Safari's Wasm stacks show function names. if grep -q 'link_libs=' emscripten/build.sh; then echo 'Render360 Portal: SIDE_MODULEs were returned to load-time linking; Source requires runtime dlopen.' >&2 exit 1 diff --git a/emscripten/assets/r360-controller.js b/emscripten/assets/r360-controller.js index b8c2fec578..ee1c5090d3 100644 --- a/emscripten/assets/r360-controller.js +++ b/emscripten/assets/r360-controller.js @@ -64,6 +64,10 @@ font: 600 9px -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; color: #e9eaee; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } body.r360-playing #r360c.r360c-on { display: block; } + #r360c { transition: opacity .45s ease; } + /* Fades out of the way when the screen is not being touched; any touch + brings it straight back (and still presses the button under it). */ + #r360c.r360c-idle { opacity: .16; } /* Dark, faintly tinted glass with a hairline border, as in the reference; the fill is translucent so the game shows through. */ #r360c button, #r360c-stick { pointer-events: auto; position: absolute; appearance: none; margin: 0; padding: 0; @@ -437,6 +441,22 @@ apply(); }; + // Idle fade. + const IDLE_MS = 4000; + let idleTimer = 0; + function wake() { + root.classList.remove('r360c-idle'); + clearTimeout(idleTimer); + idleTimer = setTimeout(() => { + // Never fade while a control is held. + if (stickPointer !== null || held.size) { wake(); return; } + root.classList.add('r360c-idle'); + }, IDLE_MS); + } + for (const type of ['pointerdown', 'touchstart']) { + document.addEventListener(type, wake, { capture: true, passive: true }); + } + function mount() { root.dataset.mode = mode; const label = stick.querySelector('.r360c-label'); @@ -444,6 +464,7 @@ document.body.appendChild(root); layout(); apply(); + wake(); } window.addEventListener('resize', layout); diff --git a/emscripten/build.sh b/emscripten/build.sh index 2682444d82..154eb0ca0c 100755 --- a/emscripten/build.sh +++ b/emscripten/build.sh @@ -372,12 +372,12 @@ echo "Render360 Portal: required filesystem/engine/ToGL module set present" # forwards them to the Source pthread where WORKERFS exposes them read-only. # Source then opens the retail VPKs and performs its own range reads on demand. # WORKERFS is not part of the default JS filesystem, so link it explicitly. -EMCC_FORCE_STDLIBS=libc,libc++,libc++abi emcc -Os \ +EMCC_FORCE_STDLIBS=libc,libc++,libc++abi emcc -Os --profiling-funcs \ -sUSE_BZIP2=1 -sUSE_SDL=2 -sUSE_FREETYPE=1 -sUSE_LIBJPEG=1 -sUSE_LIBPNG -sMALLOC=dlmalloc \ -sMAIN_MODULE -sINCLUDE_FULL_LIBRARY=1 \ -sINITIAL_MEMORY=384mb -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1024mb -sMEMORY_GROWTH_LINEAR_STEP=32mb \ -sSHARED_MEMORY=1 -sUSE_PTHREADS -sPTHREAD_POOL_SIZE=2 -sPTHREAD_POOL_SIZE_STRICT=0 \ - -sFULL_ES3 -sSTACK_SIZE=4mb -sDEFAULT_PTHREAD_STACK_SIZE=1mb --shell-file=emscripten/shell.html \ + -sFULL_ES3 -sSTACK_SIZE=16mb -sDEFAULT_PTHREAD_STACK_SIZE=1mb --shell-file=emscripten/shell.html \ -sASSERTIONS=1 -sSTACK_OVERFLOW_CHECK=1 \ -sPROXY_TO_PTHREAD -sOFFSCREENCANVASES_TO_PTHREAD="#canvas" -sOFFSCREENCANVAS_SUPPORT=1 \ -lworkerfs.js \ diff --git a/emscripten/pre.js b/emscripten/pre.js index bcf517eb49..0cae8d0ed8 100644 --- a/emscripten/pre.js +++ b/emscripten/pre.js @@ -95,13 +95,15 @@ let render360LogTailDirty = false function render360RememberLine(text) { const line = String(text || '').trim() if(!line) return + // Crash stacks are long and are the whole point; keep them intact. + const limit = line.startsWith('[Render360 worker stack]') ? 3000 : 300 if(RENDER360_NOTABLE_RE.test(line) && render360Notable.length < 60) { const last = render360Notable[render360Notable.length - 1] - if(!last || !last.endsWith(line.slice(0, 300))) { - render360Notable.push(`${((Date.now() - render360Now) / 1000).toFixed(1)}s ${line.slice(0, 300)}`) + if(!last || !last.endsWith(line.slice(0, limit))) { + render360Notable.push(`${((Date.now() - render360Now) / 1000).toFixed(1)}s ${line.slice(0, limit)}`) } } - render360LogTail.push(`${((Date.now() - render360Now) / 1000).toFixed(1)}s ${line.slice(0, 300)}`) + render360LogTail.push(`${((Date.now() - render360Now) / 1000).toFixed(1)}s ${line.slice(0, limit)}`) if(render360LogTail.length > RENDER360_LOG_TAIL_LINES) render360LogTail.splice(0, render360LogTail.length - RENDER360_LOG_TAIL_LINES) render360LogTailDirty = true } @@ -826,7 +828,9 @@ if(render360IsWindow && !render360ProbableProcessReload) { if(!render360IsWindow && typeof self !== 'undefined' && typeof self.addEventListener === 'function') { self.addEventListener('error', event => { const error = event?.error - const stack = String(error?.stack || '').split('\n').slice(0, 24).join(' | ') + const stack = String(error?.stack || '').split('\n').slice(0, 40) + .map(frame => frame.replace(/@\[wasm code\]$/, '').replace(/^(\d+)@wasm-function\[\1\]$/, 'f$1')) + .join(' | ') render360Log(`[Render360 worker stack] ${error?.message || event?.message || 'error'} :: ${stack || ''}`) }) } diff --git a/wscript b/wscript index 2a89431019..2cb8ed5da8 100644 --- a/wscript +++ b/wscript @@ -559,6 +559,9 @@ def configure(conf): # (e.g. CThread::Start from tier0), so it aborted at load with # "undefined symbol". It only saved ~5% anyway. linkflags += ['-sSIDE_MODULE=1', '-Wl,--allow-multiple-definition'] + # Keep function names in the shipped modules so Safari's Wasm stack + # traces name the failing code on iPhone (diagnostics), not wasm-function[N]. + linkflags += ['--profiling-funcs'] flags += ['-sFULL_ES3', '-sMALLOC=mimalloc'] if conf.env.DEST_OS == 'freebsd':