Fix polyphonic audio streams with id > 1 cannot be stopped or changed (MSVC mis-optimization)

This commit is contained in:
David Trallero 2024-07-15 13:52:19 +08:00 committed by Rémi Verschelde
parent e25f3c0d38
commit 67ece3dc63
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 7 additions and 7 deletions

View file

@ -34,6 +34,9 @@
#include "scene/main/scene_tree.h"
#include "servers/audio_server.h"
constexpr uint64_t ID_MASK = 0xFFFFFFFF;
constexpr uint64_t INDEX_SHIFT = 32;
Ref<AudioStreamPlayback> AudioStreamPolyphonic::instantiate_playback() {
Ref<AudioStreamPlaybackPolyphonic> playback;
playback.instantiate();
@ -252,14 +255,14 @@ AudioStreamPlaybackPolyphonic::ID AudioStreamPlaybackPolyphonic::play_stream(con
}
AudioStreamPlaybackPolyphonic::Stream *AudioStreamPlaybackPolyphonic::_find_stream(int64_t p_id) {
uint32_t index = p_id >> INDEX_SHIFT;
uint32_t index = static_cast<uint64_t>(p_id) >> INDEX_SHIFT;
if (index >= streams.size()) {
return nullptr;
}
if (!streams[index].active.is_set()) {
return nullptr; // Not active, no longer exists.
}
int64_t id = p_id & ID_MASK;
int64_t id = static_cast<uint64_t>(p_id) & ID_MASK;
if (streams[index].id != id) {
return nullptr;
}

View file

@ -60,11 +60,8 @@ public:
class AudioStreamPlaybackPolyphonic : public AudioStreamPlayback {
GDCLASS(AudioStreamPlaybackPolyphonic, AudioStreamPlayback)
enum {
INTERNAL_BUFFER_LEN = 128,
ID_MASK = 0xFFFFFFFF,
INDEX_SHIFT = 32
};
constexpr static uint32_t INTERNAL_BUFFER_LEN = 128;
struct Stream {
SafeFlag active;
SafeFlag pending_play;