!Q error when deleting tile in TileMap

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Vadalken

Background info:
I am using a tilemap layer to keep track of available tiles. This way I can also toggle the visibility of that layer to show the player what tiles are available.
When I delete a tile I use the this function:

func clear_tile(tile):
	get_node("TileMap").set_cell(3, tile, 2, Vector2i.ZERO)

which causes this error:

Condition "!Q" is true.
  <C++ Source>   scene/2d/tile_map.cpp:2100 @ set_cell()

which relates to this part of engine code:

As far as I can see I am using the set_cell function correctly, and I don’t understand why this error is thrown. I get when the error is thrown, just not why the programmers decided it is needed. I am doing exactly the same as the function

void TileMap::erase_cell(int p_layer, const Vector2i &p_coords)

which also throws the same error.

What is the “!Q is true” error for and will it actually cause any problems?

I know there are ways I can avoid needing to erase tiles (like making the tiles transparent instead), but I think my current solution is good for simplicity and code clarity.

:bust_in_silhouette: Reply From: Vadalken

When does the error happen?
When set_cell is used on a cell in a disabled layer. The erase_cell function is really just a call to set_cell, so it produces the same error.

Why does the error happen?
It is essentially an early return to prevent bigger errors. The Condition "!Q" is true. error is thrown, preventing the engine going ham on null.

What does the Error mean?
The engine creates “stuff” to handle layers. When a layer is disabled, the engine removes the “stuff” it made to handle it (the “stuff” is remade if/when the layer is enabled again).
Layers are partitioned into quadrants as part of the “stuff”-making process. In the Condition "!Q" is true. error message, Q is a pointer to a quadrant. If the relevant layer is disabled, then Q is pointing to null(since there is no “stuff”). That is exactly what Condition "!Q" is true. means (“There is no ‘stuff’ to manipulate.”).

Will this error cause any problems?
I don’t think so. The set_cell function changes the cell in the layer before the error happens, so it does what you would expect. Once the layer with the cell gets enabled; the “stuff” will be made using the layer and it will be the same as what you would get if set_cell is used while the layer is enabled.