Skip to content

[OpenAL] Fix sourceSeek crash on stopped sources - #26770

Open
uniformization wants to merge 3 commits into
emscripten-core:mainfrom
uniformization:main
Open

[OpenAL] Fix sourceSeek crash on stopped sources#26770
uniformization wants to merge 3 commits into
emscripten-core:mainfrom
uniformization:main

Conversation

@uniformization

@uniformization uniformization commented Apr 24, 2026

Copy link
Copy Markdown

If you tried to use AL_SEC_OFFSET on a stopped audio source, sourceSeek would throw a TypeError because audioBuf would be undefined.

@sbc100 sbc100 changed the title Fix sourceSeek crash on stopped sources [OpenAL] Fix sourceSeek crash on stopped sources Apr 24, 2026

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you maybe modify one of the existing tests in test_browser.py or test_inerative.py to cover this?

@uniformization

uniformization commented Apr 25, 2026

Copy link
Copy Markdown
Author

Could you maybe modify one of the existing tests in test_browser.py or test_inerative.py to cover this?

@sbc100 I have added a test to test_openal_playback.c to cover the issue.

Comment thread src/lib/libopenal.js Outdated
Comment thread test/openal/test_openal_playback.c
Comment thread src/lib/libopenal.js Outdated
Comment thread src/lib/libopenal.js Outdated
@uniformization

Copy link
Copy Markdown
Author

@sbc100 The issues have been resolved, let me know if the fix for the failing/passing the test is good

#endif
#else
usleep(700000);
playSource((void*)(sources[0]));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in this mode you are calling playSource directly from the main function. Is it important for this test that you don't go via emscripten_async_call (like the !TEST_LOOPED_PLAYBACK case above?)

@uniformization uniformization Jul 27, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbc100 Yes, if unpatched, it will error, but the test will not fail if I call it through emscripten_async_call.

@sbc100

sbc100 commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

I did some research and came up with a slightly different fix/test: #27426. I'm happy to credit you as a co-author on that PR. What do you think of my alternative change?

sbc100 added a commit to sbc100/emscripten that referenced this pull request Jul 28, 2026
Fix a crash in `sourceSeek` when called on a stopped source by resetting
`bufsProcessed = 0` before evaluating buffer durations.

This replaces emscripten-core#26770. Unlike emscripten-core#26770, which added a top-level check on
`src.bufQueue[0]`, this change handles zero/dummy buffers and empty
queues safely anywhere in `bufQueue` via `for .. of` iteration and
`audioBuf?.duration ?? 0.0`. It also adds assertions to
`test_openal_error.c` to verify state correctness after seeking.

See: emscripten-core#26770
sbc100 added a commit to sbc100/emscripten that referenced this pull request Jul 28, 2026
Fix a crash in `sourceSeek` when called on a stopped source by resetting
`bufsProcessed = 0` before evaluating buffer durations.

This replaces emscripten-core#26770. Unlike emscripten-core#26770, which added a top-level check on
`src.bufQueue[0]`, this change handles zero/dummy buffers and empty
queues safely anywhere in `bufQueue` via `for .. of` iteration and
`audioBuf?.duration ?? 0.0`. It also adds assertions to
`test_openal_error.c` to verify state correctness after seeking.

See: emscripten-core#26770
sbc100 added a commit to sbc100/emscripten that referenced this pull request Jul 28, 2026
Fix a crash in `sourceSeek` when called on a stopped source by resetting
`bufsProcessed = 0` before evaluating buffer durations.

This replaces emscripten-core#26770. Unlike emscripten-core#26770, which added a top-level check on
`src.bufQueue[0]`, this change handles zero/dummy buffers and empty
queues safely anywhere in `bufQueue` via `for .. of` iteration and
`audioBuf?.duration ?? 0.0`. It also adds assertions to
`test_openal_error.c` to verify state correctness after seeking.

See: emscripten-core#26770
sbc100 added a commit to sbc100/emscripten that referenced this pull request Jul 29, 2026
Fix a crash in `sourceSeek` when called on a stopped source by resetting
`bufsProcessed = 0` before evaluating buffer durations.

This replaces emscripten-core#26770. Unlike emscripten-core#26770, which added a top-level check on
`src.bufQueue[0]`, this change handles zero/dummy buffers and empty
queues safely anywhere in `bufQueue` via `for .. of` iteration and
`audioBuf?.duration ?? 0.0`. It also adds assertions to
`test_openal_error.c` to verify state correctness after seeking.

See: emscripten-core#26770
sbc100 added a commit that referenced this pull request Jul 29, 2026
Fix a crash in `sourceSeek` when called on a stopped source by resetting
`bufsProcessed = 0` before evaluating buffer durations.

This replaces #26770. Unlike #26770, which added a top-level check on
`src.bufQueue[0]`, this change handles zero/dummy buffers and empty
queues safely anywhere in `bufQueue` via `for .. of` iteration and
`audioBuf?.duration ?? 0.0`. It also adds assertions to
`test_openal_error.c` to verify state correctness after seeking.

See: #26770
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants