Skip to content

Commit

Permalink
Merge pull request #97739 from adamscott/fix-get-bus-null
Browse files Browse the repository at this point in the history
[Web] Make audio bus fetching more resilient to errors
  • Loading branch information
akien-mga committed Oct 2, 2024
2 parents 8ac4a81 + 7a634ad commit 2e14492
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions platform/web/js/libs/library_godot_audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
},

Expand Down Expand Up @@ -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);
},

/**
Expand All @@ -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);
},

Expand All @@ -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);
},

Expand All @@ -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);
},
},
Expand Down

0 comments on commit 2e14492

Please sign in to comment.