Skip to content

Editor crash when moving a GridMap selection that contains invalid item IDs #105542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RobTheFiveNine opened this issue Apr 18, 2025 · 1 comment · Fixed by #105664
Closed

Editor crash when moving a GridMap selection that contains invalid item IDs #105542

RobTheFiveNine opened this issue Apr 18, 2025 · 1 comment · Fixed by #105664

Comments

@RobTheFiveNine
Copy link
Contributor

Tested versions

  • Reproducible in v4.4.1.stable.official [49a5bc7]

System information

Godot v4.4.1.stable - Ubuntu 25.04 25.04 on X11 - X11 display driver, Multi-window, 2 monitors - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3070 Ti (nvidia; 570.133.07) - 12th Gen Intel(R) Core(TM) i9-12900F (24 threads)

Issue description

If you attempt to use the select and move tools in the GridMap while a reference to a now non-existent mesh library item is in the GridMap, it will crash with the following:

ERROR: Requested for nonexistent MeshLibrary item '1'.                                                           
   at: get_item_mesh (scene/resources/3d/mesh_library.cpp:221)

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.4.1.stable.official (49a5bc7b616bd04689a2c89e89bda41f50241464)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x45810) [0x75d825645810] (??:0)
[2] ~/.local/bin/godot() [0xf9a45b] (??:0)
[3] ~/.local/bin/godot() [0x4513ff4] (??:0)
[4] ~/.local/bin/godot() [0x47d555a] (??:0)
[5] ~/.local/bin/godot() [0x80ba73] (??:0)
[6] ~/.local/bin/godot() [0xff6b76] (??:0)
[7] ~/.local/bin/godot() [0x18d15b6] (??:0)
[8] ~/.local/bin/godot() [0x1fcbfc8] (??:0)
[9] ~/.local/bin/godot() [0x1fa8d7c] (??:0)
[10] ~/.local/bin/godot() [0x47d555a] (??:0)
[11] ~/.local/bin/godot() [0x2a3ac76] (??:0)
[12] ~/.local/bin/godot() [0x2985808] (??:0)
[13] ~/.local/bin/godot() [0x29865b6] (??:0)
[14] ~/.local/bin/godot() [0x299d7bc] (??:0)
[15] ~/.local/bin/godot() [0x4f18ecb] (??:0)
[16] ~/.local/bin/godot() [0x4ced85] (??:0)
[17] ~/.local/bin/godot() [0x442a293] (??:0)
[18] ~/.local/bin/godot() [0x442c14f] (??:0)
[19] ~/.local/bin/godot() [0x4dc1e3] (??:0)
[20] ~/.local/bin/godot() [0x41e7a0] (??:0)
[21] /lib/x86_64-linux-gnu/libc.so.6(+0x2a338) [0x75d82562a338] (??:0)
[22] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x8b) [0x75d82562a3fb] (??:0)
[23] ~/.local/bin/godot() [0x44297a] (??:0)
-- END OF BACKTRACE --
================================================================

Steps to reproduce

In the MRP, open gridmap_scene.tscn, select the GridMap node and then use the selection tool (Q) to select all the visible tiles like this:

Image

With these items selected, use the move tool (X) and the tiles will be able to be moved without issue.

Now, to cause the crash, change the mesh library assigned to the GridMap node to missing_tile.meshlib and see the red tiles (Tile2) disappear:

Image

With the new mesh library assigned, repeat the previously steps to select and move the tiles, and the crash will occur.

Minimal reproduction project (MRP)

invalid-gridmap-items-crash.zip

@RobTheFiveNine
Copy link
Contributor Author

Also, as a work around for anyone who runs into this issue - if you drop the below script into your project, you can add a GridMapCleaner node into your scene, assign the problematic GridMap to it and click the button in the inspector pane to remove reference to any mesh library items that are no longer valid (with the currently assigned mesh library):

@tool
class_name GridMapCleaner
extends Node


@export_tool_button("Remove Invalid Items", "Callable") var remove_invalid_items_action: Callable = remove_invalid_items

@export var grid_map: GridMap


func remove_invalid_items() -> void:
	if not grid_map:
		print("GridMapCleaner: GridMap has not been set, aborting.")
		return

	var mesh_library: MeshLibrary = grid_map.mesh_library
	var used_cells: Array[Vector3i] = grid_map.get_used_cells()

	for i in range(used_cells.size()):
		var cell: Vector3i = used_cells[i]
		var item_index: int = grid_map.get_cell_item(cell)

		var mesh: Mesh = mesh_library.get_item_mesh(item_index)

		if not mesh:
			print("GridMapCleaner: Removing invalid mesh ID (", item_index, ") at ", cell)
			grid_map.set_cell_item(cell, GridMap.INVALID_CELL_ITEM)

	print("GridMapCleaner: Finished removing invalid items.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants