From acf2d2d7014e833a3b3917d94905da6b0bd8570a Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 10 Apr 2020 15:50:53 +0200 Subject: [PATCH] Fix 2 multithreading related crashes. --- world/default/voxel_chunk_default.cpp | 14 +++++++------- world/voxel_world.cpp | 2 +- world/voxel_world_editor.cpp | 3 ++- world/voxel_world_editor.h | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/world/default/voxel_chunk_default.cpp b/world/default/voxel_chunk_default.cpp index 882e5ff..8fa1c69 100644 --- a/world/default/voxel_chunk_default.cpp +++ b/world/default/voxel_chunk_default.cpp @@ -1031,10 +1031,10 @@ void VoxelChunkDefault::_build_phase(int phase) { return; } - //if (_is_build_threaded) { - // set_active_build_phase_type(BUILD_PHASE_TYPE_PHYSICS_PROCESS); - // return; - //} + if (_is_build_threaded) { //&& Engine::get_singleton()->is_editor_hint()? + set_active_build_phase_type(BUILD_PHASE_TYPE_PHYSICS_PROCESS); + return; + } if (!has_meshes(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_BODY)) { create_colliders(MESH_INDEX_TERRARIN); @@ -1092,9 +1092,6 @@ void VoxelChunkDefault::_build_phase(int phase) { RID mesh_rid = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0); - if (mesh_rid != RID()) - VS::get_singleton()->mesh_clear(mesh_rid); - Array temp_mesh_arr = mesher->build_mesh(); if (mesh_rid == RID()) { @@ -1106,6 +1103,9 @@ void VoxelChunkDefault::_build_phase(int phase) { mesh_rid = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0); } + if (VS::get_singleton()->mesh_get_surface_count(mesh_rid) > 0) + VS::get_singleton()->mesh_remove_surface(mesh_rid, 0); + VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); if (_library->get_material(0).is_valid()) diff --git a/world/voxel_world.cpp b/world/voxel_world.cpp index c254342..251d8af 100644 --- a/world/voxel_world.cpp +++ b/world/voxel_world.cpp @@ -371,7 +371,7 @@ bool VoxelWorld::is_position_walkable(const Vector3 &p_pos) { } void VoxelWorld::on_chunk_mesh_generation_finished(Ref p_chunk) { - emit_signal("chunk_mesh_generation_finished", p_chunk); + call_deferred("emit_signal", "chunk_mesh_generation_finished", p_chunk); } Vector VoxelWorld::get_chunks() { diff --git a/world/voxel_world_editor.cpp b/world/voxel_world_editor.cpp index 87c0b50..1eacf30 100644 --- a/world/voxel_world_editor.cpp +++ b/world/voxel_world_editor.cpp @@ -86,7 +86,7 @@ bool VoxelWorldEditor::forward_spatial_input_event(Camera *p_camera, const Refadd_control_to_menu_panel(spatial_editor_hb); } VoxelWorldEditor::~VoxelWorldEditor() { + _world = NULL; } void VoxelWorldEditor::_node_removed(Node *p_node) { diff --git a/world/voxel_world_editor.h b/world/voxel_world_editor.h index d85acd9..3a119e1 100644 --- a/world/voxel_world_editor.h +++ b/world/voxel_world_editor.h @@ -76,7 +76,7 @@ protected: public: virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref &p_event) { return voxel_world_editor->forward_spatial_input_event(p_camera, p_event); } - virtual String get_name() const { return "VoxelWorld"; } + virtual String get_name() const { return "VoxelWorldEditor"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_object); virtual bool handles(Object *p_object) const;