Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting AudioStreamPlayer's stream causes crash in HTML5 threads build #52010

Open
Tracked by #76797
MickeMakaron opened this issue Aug 23, 2021 · 8 comments
Open
Tracked by #76797

Comments

@MickeMakaron
Copy link
Contributor

Godot version

3.3.stable, 3.3.3.stable

System information

Windows 10, Chrome 92.0.4515.159

Issue description

When setting the stream of an AudioStreamPlayer in a threads build in HTML5, the game sometimes crashes.

The crash happens in both debug and release. It does not happen when running the game natively.

It looks like a race condition. I've attached a reproduction project that resets the stream every frame to trigger the crash.

Here's an example error stacktrace:
image

Steps to reproduce

(Tested with 3.3.3 and 3.3.0)

  1. Run the exported reproduction project in the browser with threads enabled.
  2. Within a few seconds the game crashes. See the web console for errors.

Minimal reproduction project

audio_sample_thread_crash.zip

@Calinou
Copy link
Member

Calinou commented Aug 23, 2021

cc @Faless

Can you reproduce this in an HTML5 exported project with threads disabled?

@MickeMakaron
Copy link
Contributor Author

cc @Faless

Can you reproduce this in an HTML5 exported project with threads disabled?

No. When running with a non-threads build the crash doesn't occur (tested with 3.3.3).

@ellenhp
Copy link
Contributor

ellenhp commented Aug 27, 2021

If I had to guess, I'd say WAV streams likely don't have this same issue. I'd also say that it seems likely the AudioStreamPlayer thinks it's currently playing audio, since the only time AudioStreamPlayer::set_stream ever calls mix is in a last-ditch effort to avoid a pop on stream change. Here's the comment in this block of code:

//changing streams out of the blue is not a great idea, but at least
//let's try to somehow avoid a click

As a workaround, you can try converting the stream to a wav if it's a short sound effect. Otherwise, you could try creating a new AudioStreamPlayer and queue_freeing the old one each time you need to change the stream. Calling queue_free on a playing audio stream player will cause a click though, so it might be wise to call stop then wait a frame or two first to ensure that the player has had a chance to fade out. I'll see if I can come up with a fix for this at some point though. I'm pretty sure it will be fixed in master by #51296

I'm very curious to know if either of these workarounds will work, and it might be helpful for others in the future or for whoever ends up fixing this bug, so reporting back will be helpful :)

@lilybugged
Copy link

Changing my OGGs to WAVs on my sound effects completely fixed this issue on my and my users' end.

@akien-mga
Copy link
Member

I'm pretty sure it will be fixed in master by #51296

That sounds likely. I guess we'll have to wait for a WebGL renderer to make a comeback in master to test it though (unless this can be tested headless? @Faless)

A crash is pretty bad so it would still be important to find a fix for 3.x if we can, even if not as thorough as the 4.0 one.

@akien-mga akien-mga added this to the 3.4 milestone Sep 17, 2021
@akien-mga akien-mga modified the milestones: 3.4, 3.5 Nov 8, 2021
@jitspoe
Copy link
Contributor

jitspoe commented Nov 10, 2021

EDIT: Seems my crash may be a different bug, so I've opened a separate issue here: #54866

I may be having a different issue, but I'm getting occasional crashes in native builds in FWOP (https://github.com/jitspoe/floppy_fish/tree/main/floppy_fish_godot) in both 3.3.4 and 3.4 which I SUSPECT are related to audio. Unfortunately, I haven't been able to reproduce the crash with a debugger attached. Been trying to reproduce for the past hour or 2. On windows, the game just instantly quits with no error. On Linux, somebody got this:

(No debugging symbols found in FWOP.x86_64) (gdb) run Starting program: /home/christopher/Downloads/FWOP_linux_update/FWOP.x86_64 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7ffff6eda700 (LWP 14976)] ERROR: _get_modified_time: Method failed. Returning: 0 At: drivers/unix/file_access_unix.cpp:322. Godot Engine v3.3.4.stable.official.faf3f883d - https://godotengine.org [Detaching after fork from child pr

Other thing that makes me think it's audio related is when I fade out the music in, there's a pop in the ambient sound, and things like checking if an audio stream was playing too frequently caused major stutters.

@akien-mga
Copy link
Member

akien-mga commented Nov 10, 2021

@jitspoe I would suggest opening a new issue for this. It might be related but that's a wild guess for now and this issue was specifically about the HTML5 multi-threaded build (though that doesn't mean the issue couldn't happen on other platforms).

We can always merge them together if/when we figure out that they're the same root cause, but if they aren't, debugging two bugs in the same issue is tricky :)

Edit: Also, I know it was a trap to get me to spent 10 min on your frustrating game not managing to go anywhere :P No crash so far, but if you manage to reproduce it somewhat reliably on Linux, you could use a debug template from https://github.com/Calinou/godot-debug-builds/releases to have a detailed crash stacktrace.

@jitspoe
Copy link
Contributor

jitspoe commented Nov 10, 2021

Edit: Also, I know it was a trap to get me to spent 10 min on your frustrating game not managing to go anywhere :P

LOL!

I didn't want to open a new issue unless I confirmed it WASN'T related, especially since all the symptoms sounded similar, and it's like a 1/100 crash -- very difficult to know if it's fixed or not. It's crashed on me like 3-4 times over the course of 30-40 hours.

I wasn't the one crashing on Linux, so I'll forward that info on and see if we can get any further info.

Side note: I fixed the popping during music fade out by stopping the music BEFORE the volume reached 0. Not sure if that was related to the crash at all, as I haven't been able to reproduce it with or without the change recently. :|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants