godot icon indicating copy to clipboard operation
godot copied to clipboard

Crash when opening TileMap terrains tab

Open dizeeee opened this issue 2 years ago • 1 comments

Godot version

4.0 Beta 1

System information

Windows 10, Ryzen 5900x, Nvidia GTX 1080ti, Vulkan Clustered

Issue description

The editor crashes when trying to view terrains for the attached project. This is most likely due to an unused terrain I deleted.

Steps to reproduce

  • Open the world scene in the project
  • Open the tilemap tab at the bottom of the screen
  • Click the terrains tab

Minimal reproduction project

New Game Project.zip

dizeeee avatar Sep 18 '22 21:09 dizeeee

CrashHandlerException: Program crashed
Engine version: Godot Engine v4.0.beta.custom_build (20d6672846b3fd1537603ac080116dcc914c10e3)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] TileSet::generate_terrains_icons (C:\godot_source\scene\resources\tile_set.cpp:1766)
[1] TileSet::generate_terrains_icons (C:\godot_source\scene\resources\tile_set.cpp:1766)
[2] TileMapEditorTerrainsPlugin::_update_terrains_tree (C:\godot_source\editor\plugins\tiles\tile_map_editor.cpp:3154)
[3] TileMapEditorTerrainsPlugin::edit (C:\godot_source\editor\plugins\tiles\tile_map_editor.cpp:3307)
[4] TileMapEditor::_tab_changed (C:\godot_source\editor\plugins\tiles\tile_map_editor.cpp:3606)
[5] CallableCustomMethodPointer<TileMapEditor,int>::call (C:\godot_source\core\object\callable_method_pointer.h:105)
[6] Callable::callp (C:\godot_source\core\variant\callable.cpp:51)
[7] Object::emit_signalp (C:\godot_source\core\object\object.cpp:1046)
[8] Object::emit_signal<int> (C:\godot_source\core\object\object.h:873)
[9] TabBar::gui_input (C:\godot_source\scene\gui\tab_bar.cpp:277)
[10] Control::_call_gui_input (C:\godot_source\scene\gui\control.cpp:1719)
[11] Viewport::_gui_call_input (C:\godot_source\scene\main\viewport.cpp:1299)
[12] Viewport::_gui_input_event (C:\godot_source\scene\main\viewport.cpp:1534)
[13] Viewport::push_input (C:\godot_source\scene\main\viewport.cpp:2751)
[14] Window::_window_input (C:\godot_source\scene\main\window.cpp:1094)
[15] CallableCustomMethodPointer<Window,Ref<InputEvent> const &>::call (C:\godot_source\core\object\callable_method_pointer.h:104)
[16] Callable::callp (C:\godot_source\core\variant\callable.cpp:51)
[17] DisplayServerWindows::_dispatch_input_event (C:\godot_source\platform\windows\display_server_windows.cpp:2094)
[18] Input::_parse_input_event_impl (C:\godot_source\core\input\input.cpp:662)
[19] Input::flush_buffered_events (C:\godot_source\core\input\input.cpp:885)
[20] DisplayServerWindows::process_events (C:\godot_source\platform\windows\display_server_windows.cpp:1801)
[21] OS_Windows::run (C:\godot_source\platform\windows\os_windows.cpp:895)
[22] widechar_main (C:\godot_source\platform\windows\godot_windows.cpp:179)
[23] _main (C:\godot_source\platform\windows\godot_windows.cpp:203)
[24] main (C:\godot_source\platform\windows\godot_windows.cpp:215)
[25] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[26] BaseThreadInitThunk
-- END OF BACKTRACE --

Looks similar to #62630

KoBeWi avatar Sep 18 '22 21:09 KoBeWi

Fixing the crash is as simple as changing this https://github.com/godotengine/godot/blob/57ffc4d82c773a513c8d122d859f07759c8c7da3/scene/resources/tile_set.cpp#L1764 to if (tile_data->get_terrain() >= 0 && tile_data->get_terrain() < bit_counts.size()) {

This results in empty preview image and this error: core\io\image.cpp:2668 - Condition "format != p_src->format" is true.

I think a better fix would be preventing creation of invalid terrains like in the MRP, but not sure how it have happened.

KoBeWi avatar Oct 05 '22 15:10 KoBeWi

@KoBeWi thank you for your quick fix

BearYear2 avatar Apr 19 '23 19:04 BearYear2

I encountered this bug today. It happened because I created terrains, then added them to my scene, then deleted the terrain from here: Screen Shot 2023-07-01 at 10 36 50 pm

After this, my scene file contained references to the non-existent terrains, and clicking the terrain tab for the TileMap node in the scene would hard crash Godot.

I found that if I manually edit the scene file to remove the references to the deleted scenes, then it prevents the crash. To do this, first open your scene file in a text editor, and find the section which starts with:

[sub_resource type="TileSet"

In the sample game files in the original post this section looks like this:

[sub_resource type="TileSet" id="TileSet_45lrc"]
physics_layer_0/collision_layer = 1
terrain_set_0/mode = 0
terrain_set_0/terrain_0/name = "Walls"
terrain_set_0/terrain_0/color = Color(0.290196, 0.321569, 0.756863, 1)
terrain_set_1/mode = 2
terrain_set_1/terrain_0/name = "Path"
terrain_set_1/terrain_0/color = Color(0.780392, 0.137255, 0.380392, 1)
sources/1 = SubResource("TileSetAtlasSource_whx14")
sources/2 = SubResource("TileSetAtlasSource_kjyec")

You can see that there are two terrain sets, 0 and 1, with a single terrain each, both numbered as terrain 0 for their respective terrain sets.

However, if you search the file for terrain = 1, you will find something like this occurs multiple times:

0:0/0 = 0
0:0/0/terrain_set = 1
0:0/0/terrain = 1
0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
0:0/0/physics_layer_0/angular_velocity = 0.0

I assume the prefix 0:0/0 is related to the tile location and layer or something. If you search for terrain = 1, then delete all the lines matching that location, in the above sequence, then you should be able to open the terrain tab again without crashing.

Note that you will need to do this for every terrain which has been deleted from your scene. For example, you might also need to search for terrain = 2, etc.

daviewales avatar Jul 01 '23 12:07 daviewales

I also had this bug occur to me after having applied terrain and then deleting the terrain. This also caused my scene containing my tilemap to be considered corrupt, refusing to open. Luckily there wasn't much inside that scene.

It does indeed seem that the tileset retains the terrain data and should be cleaned up after having deleted the terrain.

DrunkenToast avatar Feb 16 '24 09:02 DrunkenToast

Can someone confirm this on latest master? Or 4.3.dev3?

AThousandShips avatar Feb 20 '24 18:02 AThousandShips

Closing as resolved due to lack of feedback, if this bug still occurs on recent versions please comment

AThousandShips avatar Mar 10 '24 17:03 AThousandShips