Fix a crash when a VoxelTerrain is created and deleted without ever entering the tree. Was caused by Godot creating dummy instances of VoxelTerrain just to call `get_property_list` when I open the inspector...

master
Marc Gilleron 2019-06-02 02:30:22 +01:00
parent 5ecd449acc
commit 3feb32e194
1 changed files with 7 additions and 4 deletions

View File

@ -27,13 +27,14 @@ VoxelTerrain::VoxelTerrain() {
VoxelTerrain::~VoxelTerrain() {
print_line("Destroying VoxelTerrain");
// Schedule saving of all modified blocks,
// without copy because we are destroying the map anyways
save_all_modified_blocks(false);
if (_stream_thread) {
// Schedule saving of all modified blocks,
// without copy because we are destroying the map anyways
save_all_modified_blocks(false);
memdelete(_stream_thread);
}
if (_block_updater) {
memdelete(_block_updater);
}
@ -250,6 +251,8 @@ void VoxelTerrain::immerge_block(Vector3i bpos) {
void VoxelTerrain::save_all_modified_blocks(bool with_copy) {
ERR_FAIL_COND(_stream_thread == nullptr);
// That may cause a stutter, so should be used when the player won't notice
_map->for_all_blocks(ScheduleSaveAction{ _blocks_to_save, with_copy });