From 87d387388c3aefda11c6f63927e251e751385c80 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 24 Mar 2020 18:42:01 +0100 Subject: [PATCH] Apparently, calling emit signal and set_process_internal form a separate thread is not smart. --- world/voxel_chunk_default.cpp | 20 +++++++++++++------- world/voxel_chunk_default.h | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/world/voxel_chunk_default.cpp b/world/voxel_chunk_default.cpp index 4d18328..28c58bf 100644 --- a/world/voxel_chunk_default.cpp +++ b/world/voxel_chunk_default.cpp @@ -293,7 +293,6 @@ void VoxelChunkDefault::next_phase() { if (_abort_build) { _current_build_phase = BUILD_PHASE_DONE; _is_generating = false; - set_process_internal(false); return; } @@ -303,13 +302,8 @@ void VoxelChunkDefault::next_phase() { if (_current_build_phase >= _max_build_phases) { _current_build_phase = BUILD_PHASE_DONE; _is_generating = false; - set_process_internal(false); - emit_signal("mesh_generation_finished", this); - - if (_voxel_world != NULL) { - _voxel_world->on_chunk_mesh_generation_finished(this); - } + call_deferred("emit_build_finished"); } } @@ -317,6 +311,14 @@ void VoxelChunkDefault::clear() { _voxel_lights.clear(); } +void VoxelChunkDefault::emit_build_finished() { + emit_signal("mesh_generation_finished", this); + + if (_voxel_world != NULL) { + _voxel_world->on_chunk_mesh_generation_finished(this); + } +} + void VoxelChunkDefault::create_colliders() { ERR_FAIL_COND(_voxel_world == NULL); @@ -1069,6 +1071,10 @@ void VoxelChunkDefault::_notification(int p_what) { } break; case NOTIFICATION_INTERNAL_PROCESS: { + if (!get_is_generating()) { + set_process_internal(false); + } + if (!get_is_generating() || !has_next_phase() || _build_step_in_progress) { return; } diff --git a/world/voxel_chunk_default.h b/world/voxel_chunk_default.h index c06d841..d6a757c 100644 --- a/world/voxel_chunk_default.h +++ b/world/voxel_chunk_default.h @@ -209,6 +209,8 @@ public: //free void free_chunk(); + void emit_build_finished(); + VoxelChunkDefault(); ~VoxelChunkDefault();