Merge pull request #97739 from adamscott/fix-get-bus-null
Some checks are pending
🔗 GHA / 📊 Static checks (push) Waiting to run
🔗 GHA / 🤖 Android (push) Blocked by required conditions
🔗 GHA / 🍏 iOS (push) Blocked by required conditions
🔗 GHA / 🐧 Linux (push) Blocked by required conditions
🔗 GHA / 🍎 macOS (push) Blocked by required conditions
🔗 GHA / 🏁 Windows (push) Blocked by required conditions
🔗 GHA / 🌐 Web (push) Blocked by required conditions
🔗 GHA / 🪲 Godot CPP (push) Blocked by required conditions

[Web] Make audio bus fetching more resilient to errors
This commit is contained in:
Rémi Verschelde 2024-10-02 23:56:55 +02:00
commit 2e14492879
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -868,7 +868,10 @@ class Bus {
* @returns {void}
*/
static move(fromIndex, toIndex) {
const movedBus = GodotAudio.Bus.getBus(fromIndex);
const movedBus = GodotAudio.Bus.getBusOrNull(fromIndex);
if (movedBus == null) {
return;
}
const buses = GodotAudio.buses.filter((_, i) => i !== fromIndex);
// Inserts at index.
buses.splice(toIndex - 1, 0, movedBus);
@ -1424,7 +1427,10 @@ const _GodotAudio = {
* @returns {void}
*/
remove_sample_bus: function (index) {
const bus = GodotAudio.Bus.getBus(index);
const bus = GodotAudio.Bus.getBusOrNull(index);
if (bus == null) {
return;
}
bus.clear();
},
@ -1454,8 +1460,17 @@ const _GodotAudio = {
* @returns {void}
*/
set_sample_bus_send: function (busIndex, sendIndex) {
const bus = GodotAudio.Bus.getBus(busIndex);
bus.setSend(GodotAudio.Bus.getBus(sendIndex));
const bus = GodotAudio.Bus.getBusOrNull(busIndex);
if (bus == null) {
// Cannot send from an invalid bus.
return;
}
let targetBus = GodotAudio.Bus.getBusOrNull(sendIndex);
if (targetBus == null) {
// Send to master.
targetBus = GodotAudio.Bus.getBus(0);
}
bus.setSend(targetBus);
},
/**
@ -1465,7 +1480,10 @@ const _GodotAudio = {
* @returns {void}
*/
set_sample_bus_volume_db: function (busIndex, volumeDb) {
const bus = GodotAudio.Bus.getBus(busIndex);
const bus = GodotAudio.Bus.getBusOrNull(busIndex);
if (bus == null) {
return;
}
bus.setVolumeDb(volumeDb);
},
@ -1476,7 +1494,10 @@ const _GodotAudio = {
* @returns {void}
*/
set_sample_bus_solo: function (busIndex, enable) {
const bus = GodotAudio.Bus.getBus(busIndex);
const bus = GodotAudio.Bus.getBusOrNull(busIndex);
if (bus == null) {
return;
}
bus.solo(enable);
},
@ -1487,7 +1508,10 @@ const _GodotAudio = {
* @returns {void}
*/
set_sample_bus_mute: function (busIndex, enable) {
const bus = GodotAudio.Bus.getBus(busIndex);
const bus = GodotAudio.Bus.getBusOrNull(busIndex);
if (bus == null) {
return;
}
bus.mute(enable);
},
},