diff options
author | David Trallero <ditiem@gmail.com> | 2024-07-15 13:52:19 +0800 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-07-22 14:08:02 +0200 |
commit | 67ece3dc63f4d9627470bffd53e31bb377b093de (patch) | |
tree | 8428f6821278b8c304e99b6c5c83d251f3d46fe7 | |
parent | e25f3c0d38d457b15a63720240736f564ce0501b (diff) | |
download | redot-engine-67ece3dc63f4d9627470bffd53e31bb377b093de.tar.gz |
Fix polyphonic audio streams with id > 1 cannot be stopped or changed (MSVC mis-optimization)
-rw-r--r-- | scene/resources/audio_stream_polyphonic.cpp | 7 | ||||
-rw-r--r-- | scene/resources/audio_stream_polyphonic.h | 7 |
2 files changed, 7 insertions, 7 deletions
diff --git a/scene/resources/audio_stream_polyphonic.cpp b/scene/resources/audio_stream_polyphonic.cpp index 45546d8dc7..e617096f3b 100644 --- a/scene/resources/audio_stream_polyphonic.cpp +++ b/scene/resources/audio_stream_polyphonic.cpp @@ -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; } diff --git a/scene/resources/audio_stream_polyphonic.h b/scene/resources/audio_stream_polyphonic.h index 01d0176c44..b49ed1b741 100644 --- a/scene/resources/audio_stream_polyphonic.h +++ b/scene/resources/audio_stream_polyphonic.h @@ -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; |