Fix 2 multithreading related crashes.

This commit is contained in:
Relintai 2020-04-10 15:50:53 +02:00
parent 1f23f61b3a
commit acf2d2d701
4 changed files with 11 additions and 10 deletions

View File

@ -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())

View File

@ -371,7 +371,7 @@ bool VoxelWorld::is_position_walkable(const Vector3 &p_pos) {
}
void VoxelWorld::on_chunk_mesh_generation_finished(Ref<VoxelChunk> p_chunk) {
emit_signal("chunk_mesh_generation_finished", p_chunk);
call_deferred("emit_signal", "chunk_mesh_generation_finished", p_chunk);
}
Vector<Variant> VoxelWorld::get_chunks() {

View File

@ -86,7 +86,7 @@ bool VoxelWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<I
bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click, int selected_voxel) {
if (!spatial_editor)
if (!spatial_editor || !_world)
return false;
Camera *camera = p_camera;
@ -200,6 +200,7 @@ VoxelWorldEditor::VoxelWorldEditor(EditorNode *p_editor) {
SpatialEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb);
}
VoxelWorldEditor::~VoxelWorldEditor() {
_world = NULL;
}
void VoxelWorldEditor::_node_removed(Node *p_node) {

View File

@ -76,7 +76,7 @@ protected:
public:
virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &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;