summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuri Sizov <11782833+YuriSizov@users.noreply.github.com>2023-04-07 12:46:53 +0200
committerGitHub <noreply@github.com>2023-04-07 12:46:53 +0200
commitf1f0e5f91d02484f45ea69b76d1b9c7c6a335109 (patch)
tree83b79f6edca92444b049f9111cb58dac5435ce3f
parent8c551374cada11b4b24045f9017d8b585d66335e (diff)
parenta5351086b0eafa659c4f4c88471d183cd991b45e (diff)
downloadredot-engine-f1f0e5f91d02484f45ea69b76d1b9c7c6a335109.tar.gz
Merge pull request #75728 from smix8/fix_audiostreamplayer2d_crash_4.x
Fix AudioStreamPlayer2D crash when PhysicsServer2D runs on thread
-rw-r--r--scene/2d/audio_stream_player_2d.cpp6
-rw-r--r--scene/2d/audio_stream_player_2d.h3
2 files changed, 7 insertions, 2 deletions
diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp
index c175edb6cb..466ffad951 100644
--- a/scene/2d/audio_stream_player_2d.cpp
+++ b/scene/2d/audio_stream_player_2d.cpp
@@ -68,7 +68,8 @@ void AudioStreamPlayer2D::_notification(int p_what) {
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
// Update anything related to position first, if possible of course.
- if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
+ if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count()) || force_update_panning) {
+ force_update_panning = false;
_update_panning();
}
@@ -109,6 +110,7 @@ void AudioStreamPlayer2D::_notification(int p_what) {
}
}
+// Interacts with PhysicsServer2D, so can only be called during _physics_process
StringName AudioStreamPlayer2D::_get_actual_bus() {
Vector2 global_pos = get_global_position();
@@ -117,6 +119,7 @@ StringName AudioStreamPlayer2D::_get_actual_bus() {
ERR_FAIL_COND_V(world_2d.is_null(), SNAME("Master"));
PhysicsDirectSpaceState2D *space_state = PhysicsServer2D::get_singleton()->space_get_direct_state(world_2d->get_space());
+ ERR_FAIL_COND_V(space_state == nullptr, SNAME("Master"));
PhysicsDirectSpaceState2D::ShapeResult sr[MAX_INTERSECT_AREAS];
PhysicsDirectSpaceState2D::PointParameters point_params;
@@ -142,6 +145,7 @@ StringName AudioStreamPlayer2D::_get_actual_bus() {
return default_bus;
}
+// Interacts with PhysicsServer2D, so can only be called during _physics_process
void AudioStreamPlayer2D::_update_panning() {
if (!active.is_set() || stream.is_null()) {
return;
diff --git a/scene/2d/audio_stream_player_2d.h b/scene/2d/audio_stream_player_2d.h
index 79a026fed2..9b23fd3943 100644
--- a/scene/2d/audio_stream_player_2d.h
+++ b/scene/2d/audio_stream_player_2d.h
@@ -61,6 +61,7 @@ private:
Vector<AudioFrame> volume_vector;
uint64_t last_mix_count = -1;
+ bool force_update_panning = false;
float volume_db = 0.0;
float pitch_scale = 1.0;
@@ -75,7 +76,7 @@ private:
void _update_panning();
void _bus_layout_changed();
- static void _listener_changed_cb(void *self) { reinterpret_cast<AudioStreamPlayer2D *>(self)->_update_panning(); }
+ static void _listener_changed_cb(void *self) { reinterpret_cast<AudioStreamPlayer2D *>(self)->force_update_panning = true; }
uint32_t area_mask = 1;