alphaTab icon indicating copy to clipboard operation
alphaTab copied to clipboard

`api.midiLoaded.on()` registered after the MIDI is loaded throws "RangeError: Maximum call stack size exceeded" (WebWorker player)

Open gabbe opened this issue 2 months ago • 0 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

I have read the contribution rules

AI authorship

AI-assisted (disclosure block included as described in AGENTS.md)

Current Behavior

[!NOTE] AI-authored disclosure (alphatab-ai-authored-v1)

Portions of this content were authored by an AI agent. The agent has read AGENTS.md and the human submitter accepts responsibility for compliance with the rules in that document.

With the default (WebWorker) player, calling api.midiLoaded.on(handler) after a score has been loaded and its MIDI generated throws immediately:

RangeError: Maximum call stack size exceeded
    at get loadedMidiInfo (https://cdn.jsdelivr.net/npm/@coderline/[email protected]/dist/alphaTab.min.js:51:517921)
    at get loadedMidiInfo (https://cdn.jsdelivr.net/npm/@coderline/[email protected]/dist/alphaTab.min.js:51:517921)
    at get loadedMidiInfo (https://cdn.jsdelivr.net/npm/@coderline/[email protected]/dist/alphaTab.min.js:51:517921)
    ...

Firefox reports the same recursion with its own wording:

InternalError: too much recursion
get loadedMidiInfo@https://cdn.jsdelivr.net/npm/@coderline/[email protected]/dist/alphaTab.min.js:51:517906
get loadedMidiInfo@https://cdn.jsdelivr.net/npm/@coderline/[email protected]/dist/alphaTab.min.js:51:517909
get loadedMidiInfo@https://cdn.jsdelivr.net/npm/@coderline/[email protected]/dist/alphaTab.min.js:51:517909
...

The same registration made before the first load works, and the handler is then called on every later loadMidiForScore().

Expected Behavior

Registering a midiLoaded handler at any time should work. Other events (scoreLoaded, playerReady) accept late registration and immediately hand the current value to the new handler; midiLoaded should do the same instead of throwing.

Steps To Reproduce

  1. Create the API with the player enabled and load any score:

    const api = new alphaTab.AlphaTabApi(el, {
      player: { enablePlayer: true, soundFont: 'https://cdn.jsdelivr.net/npm/@coderline/[email protected]/dist/soundfont/sonivox.sf2' }
    });
    api.tex('\\tempo 120 . 3.3*4');
    
  2. Wait until playerReady has fired (the MIDI is generated and loaded).

  3. Run

    api.midiLoaded.on(e => console.log('midi loaded', e));
    
  4. Observe the RangeError above. Repeating step 3 before step 1's load instead works.

Link to jsFiddle, CodePen, Project

No response

Version and Environment

[AlphaTab][VersionInfo] alphaTab 1.8.4
[AlphaTab][VersionInfo] commit: 022a45c8e42370f9e12e68949d11eada370da83d
[AlphaTab][VersionInfo] build date: 2026-07-05T14:46:18.224Z
[AlphaTab][VersionInfo] High DPI: 1
[AlphaTab][VersionInfo] Platform: Browser
[AlphaTab][VersionInfo] WebPack: false
[AlphaTab][VersionInfo] Vite: false
[AlphaTab][VersionInfo] Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36
[AlphaTab][VersionInfo] Window Size: 2560x1392
[AlphaTab][VersionInfo] Screen Size: 2560x1440

(also reproduced on Firefox/155.0)

Platform

Web

Anything else?

No response

gabbe avatar Sep 05 '26 16:09 gabbe