Godot Version
4.3
Question
I get that error when loading my game on Web, but it's fine on the Windows build. I already looked up all the similar forum posts I could find but none seemed to do the trick. Thinking it was an issue with audio needing to be triggered after a button press, I took my sound manager scene out of autoload and loaded it after a button press, but that didn't solve it. I'm super frustrated because I thought I finished every hurdle presented by designing my first game, and I wanted my game released 4 hours ago. I don't know where to start looking for a solution.
I copied this from the console on the browser in case it helps:
index.html:139 ReferenceError: invalid bus index “-1”
at Bus.getBus (index.js:9:189566)
at Object.set_sample_bus_send (index.js:9:196322)
at _godot_audio_sample_bus_set_send (index.js:9:198274)
at 086f3c36:0x4ef5f
at 086f3c36:0x14ba158
at 086f3c36:0x14b9f27
at 086f3c36:0x254157
at 086f3c36:0xb6eb0
at 086f3c36:0xc94a5
at index.js:9:11537
displayFailureNotice @ index.html:139
I figured out the solution. It’s similar to what happened here, but I initially didn’t understand the wording so let me clarify.
To fix my issue, I had to rebuild my bus setup. Make sure to delete default.bus.layout.tres. That part is very important, otherwise it might just load the old one. Then, hit Create in the audio tab to start from scratch.
A separate solution that worked for me before I remade my bus setup was going to index.js and replacing
static getBus(index){if(index<0||index>=GodotAudio.buses.length){throw new ReferenceError(`invalid bus index "${index}"`)}return GodotAudio.buses[index]}static getBusOrNull(index){if(index<0||index>=GodotAudio.buses.length){return null}return GodotAudio.buses[index]}
with
static getBus(index)
{
if (index < 0)
{
index = 0
}
if(index >= GodotAudio.buses.length)
{
throw new ReferenceError(`invalid bus index "${index}"`)
}
return GodotAudio.buses[index]
}
static getBusOrNull(index)
{
if (index < 0)
{
index = 0
}
if(index >= GodotAudio.buses.length)
{
return null
}
return GodotAudio.buses[index]
}
Could you explain how you remade your bus setup? I have the exact same issue as you, down to using your code in the index.js and having it work. But when I delete the default bus layout resource, and create a new one in the Audio tab at the bottom, it just creates the same thing as the default, with Master pointing to Speakers. Then the error persists on the web build. Is there something you changed from the default bus layout that got your custom one to work? Thanks!
Edit: Never mind, I have been a fool. I forgot that I explicitly set the AudioStreamPlayer2D.bus parameter to be a custom SFX bus for all the sound effects, and I neglected to create a custom SFX bus for it before exporting the project.