Skip to content
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

Crash when editing/opening a huge tileset atlas #86226

Closed
rockgem opened this issue Dec 16, 2023 · 34 comments · Fixed by #87470
Closed

Crash when editing/opening a huge tileset atlas #86226

rockgem opened this issue Dec 16, 2023 · 34 comments · Fixed by #87470

Comments

@rockgem
Copy link

rockgem commented Dec 16, 2023

Tested versions

4.2.1

System information

Windows 11 Godot 4.2.1

Issue description

there seems to be a bug where it crashes when editing and opening a tile set with a huge set of textures

Steps to reproduce

Create a new tileset -> Drag and drop the given atlas for editting = either going to be laggy, or crash

13_School_32x32

Minimal reproduction project (MRP)

none

@rockgem
Copy link
Author

rockgem commented Dec 16, 2023

ps. i just tested it with existing and new projects, it also sometime crashes when using relatively smaller spritesheets as well.

@fire fire changed the title crash when editing/opening a huge tileset atlas Crash when editing/opening a huge tileset atlas Dec 16, 2023
@ATreeShine
Copy link

  1. Optimize Your Textures: Ensure that your textures are not exceeding the maximum supported texture size, which is 16384×16384 pixels. For mobile GPUs, the limit is typically 4096×4096

If your textures are larger than this, consider reducing their size or splitting them into smaller textures.

  1. Import Settings: Adjust the import settings for your textures in Godot. You can set a size limit on the texture import to reduce its dimensions while preserving the aspect ratio

3 TileMap Performance: If the issue is related to the TileMap's performance, consider optimizing the TileMap. For instance, you can adjust the quadrant_size property of the TileMap to improve performance

  1. Collision Shapes: If your TileMap includes collision shapes, be aware that having a separate collision shape for each tile can cause performance issues

Try to simplify the collision shapes or use fewer of them.
5. Memory Management: Ensure that your project is not running out of memory due to the large textures. This can be particularly problematic when exporting to platforms with lower memory limits, such as HTML5

@rockgem
Copy link
Author

rockgem commented Dec 18, 2023

  1. Optimize Your Textures: Ensure that your textures are not exceeding the maximum supported texture size, which is 16384×16384 pixels. For mobile GPUs, the limit is typically 4096×4096

If your textures are larger than this, consider reducing their size or splitting them into smaller textures.

  1. Import Settings: Adjust the import settings for your textures in Godot. You can set a size limit on the texture import to reduce its dimensions while preserving the aspect ratio

3 TileMap Performance: If the issue is related to the TileMap's performance, consider optimizing the TileMap. For instance, you can adjust the quadrant_size property of the TileMap to improve performance

  1. Collision Shapes: If your TileMap includes collision shapes, be aware that having a separate collision shape for each tile can cause performance issues

Try to simplify the collision shapes or use fewer of them. 5. Memory Management: Ensure that your project is not running out of memory due to the large textures. This can be particularly problematic when exporting to platforms with lower memory limits, such as HTML5

thanks! i will try this approach. but does this explain how the tileset editor is laggy when editing it despite having smaller texture atlas?

@G-Milzink
Copy link

Same issue occurs while using a texture of only 384*320 pixels. Editor consistently crashes when creating new tiles, editing custom-data and/or setting up terrains, alternatiove tiles etc.

@rockgem
Copy link
Author

rockgem commented Dec 21, 2023

similar issue #63534

@crayonape
Copy link

Same issue occurs while using a texture of only 384*320 pixels. Editor consistently crashes when creating new tiles, editing custom-data and/or setting up terrains, alternatiove tiles etc.

Same here, it's a really small texture, but the editor keeps crashing, I can't work!

@Nualie
Copy link

Nualie commented Dec 26, 2023

Also the same, getting a freeze and crash especially when setting up tiles that take up multiple squares, even after reducing tileset size. Usually after only 2~3 of them.

@Nualie
Copy link

Nualie commented Dec 26, 2023

Also the same, getting a freeze and crash especially when setting up tiles that take up multiple squares, even after reducing tileset size. Usually after only 2~3 of them.

After investigating, the cause of the crash seems to be the editor raising this error in an infinite loop until crash:

ERROR: Condition "p_elem->_root != this" is true. at: remove (./core/templates/self_list.h:80)

Seems to be some kind of thread conflict kind of error

@Ekaitzsegurola
Copy link

Same problem here! I was working sice 2 weeks in 4.2 estable. Since yesterday when i was to change my tileset. Didnt happen before in 4.1 (the original project version). Tried in 4.2.1 and same problem. Does not crash when painting in map, crashes when making terrain, adding new terrain layer and picking the color, when activating the tiles, sometimes directly when clicking over the node with Tilemap to edit...

In any case same error in infinite loop:

ERROR: Condition "p_elem->_root != this" is true. at: remove (./core/templates/self_list.h:80)

Maybe something that was changed from 4.1? Or when upgrading the project from 4.1 to 4.2? Can i follow the code will compiling to check where is the infinite loop? (I think it may be a while loop waiting until remove that never happens but cannot guess where it comes)

My greatest tileset is 1536 x 1152, so isnt big enough

On thing i did before starting crashing was change project to Render -> Compatibility and then return back to Render -> Mobile. Can be?

@Nualie
Copy link

Nualie commented Dec 28, 2023

Same problem here! I was working sice 2 weeks in 4.2 estable. Since yesterday when i was to change my tileset. Didnt happen before in 4.1 (the original project version). Tried in 4.2.1 and same problem. Does not crash when painting in map, crashes when making terrain, adding new terrain layer and picking the color, when activating the tiles, sometimes directly when clicking over the node with Tilemap to edit...

In any case same error in infinite loop:

ERROR: Condition "p_elem->_root != this" is true. at: remove (./core/templates/self_list.h:80)

Maybe something that was changed from 4.1? Or when upgrading the project from 4.1 to 4.2? Can i follow the code will compiling to check where is the infinite loop? (I think it may be a while loop waiting until remove that never happens but cannot guess where it comes)

My greatest tileset is 1536 x 1152, so isnt big enough

On thing i did before starting crashing was change project to Render -> Compatibility and then return back to Render -> Mobile. Can be?

I'm working in Compatibility, and I created my project in 4.2 so I don't think upgrading is the issue.

@Ekaitzsegurola
Copy link

Also the same, getting a freeze and crash especially when setting up tiles that take up multiple squares, even after reducing tileset size. Usually after only 2~3 of them.

After investigating, the cause of the crash seems to be the editor raising this error in an infinite loop until crash:

ERROR: Condition "p_elem->_root != this" is true. at: remove (./core/templates/self_list.h:80)

Seems to be some kind of thread conflict kind of error

I am loading the code of editor trying to debug (it is my first time, i do not know how). I can bet the problem is in Clear() method that gets in while loop forever. if anyone knows where is called that method

Captura de pantalla 2023-12-28 170635

@AThousandShips
Copy link
Member

AThousandShips commented Dec 28, 2023

This was noticed previously but was said to be solved, can someone please provide a minimum reproduction project to make this easier to investigate, the original issue was not reproducible almost at all so fixing or investigating it was impossible

  • A small Godot project which reproduces the issue, with no unnecessary files included. Be sure to not include the .godot folder in the archive (but keep project.godot).
  • Having an MRP is very important for contributors to be able to reproduce the bug in the same way that you are experiencing it. When testing a potential fix for the issue, contributors will use the MRP to validate that the fix is working as intended.
  • If the reproduction steps are not project dependent (e.g. the bug is visible in a brand new project), you can write "N/A" in the field.
  • Drag and drop a ZIP archive to upload it (max 10 MB). Do not select another field until the project is done uploading.
  • Note for C# users: If your issue is not C#-specific, please upload a minimal reproduction project written in GDScript. This will make it easier for contributors to reproduce the issue locally as not everyone has a .NET setup available.

See:

@Nualie
Copy link

Nualie commented Dec 28, 2023

This was noticed previously but was said to be solved, can someone please provide a minimum reproduction project to make this easier to investigate, the original issue was not reproducible almost at all so fixing or investigating it was impossible

* A small Godot project which reproduces the issue, with no unnecessary files included. Be sure to not include the `.godot` folder in the archive (but keep `project.godot`).

* Having an MRP is very important for contributors to be able to reproduce the bug in the same way that you are experiencing it. When testing a potential fix for the issue, contributors will use the MRP to validate that the fix is working as intended.

* If the reproduction steps are not project dependent (e.g. the bug is visible in a brand new project), you can write "N/A" in the field.

* Drag and drop a ZIP archive to upload it (max 10 MB). **Do not select another field until the project is done uploading.**

* **Note for C# users:** If your issue is _not_ C#-specific, please upload a minimal reproduction project written in GDScript. This will make it easier for contributors to reproduce the issue locally as not everyone has a .NET setup available.

See:

* [Godot tilemaps are extremely unstable and cause crashes all the time #84892 (comment)](https://github.com/godotengine/godot/issues/84892#issuecomment-1826768773)

tilemapbug.zip

There you go, I've copied over my buggy tilemap to a blank project and stripped it down as much as the constant crashes allowed me (it used to have a script, multiple layers, more atlases etc. removing all that didn't stop the crashes from happening or change their frequency)

Interestingly, remaking a tilemap from scratch didn't show any issues, unlike copying the broken one...

@Ekaitzsegurola
Copy link

I have the same issue, i was playing since 1 hour with a new project tilemap trying to reproduce error without luck. I am going to try what @Nualie you just did to reproduce

I tryied in version 4.2 RC2 as the link and also crashes

@Ekaitzsegurola
Copy link

Ekaitzsegurola commented Dec 28, 2023

I upload the project with the bad tilemap. I removed anything else from the project. You can reproduce trying to draw the terrain like in the image below:

Captura de pantalla 2023-12-28 190558

GodotMyCrash.zip

@Ekaitzsegurola
Copy link

Ekaitzsegurola commented Dec 28, 2023

I can confirm that if the project is changed to 4.1.2 does not crash. Same for the GodotMyCrash i uploaded with minimum to reproduce. And when returning to back to 4.2.1 crashes. Something was broken between 4.1 and 4.2

An easy way to reproduce is create a new Terrain in TerrainSets of Tilemap and moving around color selector. In most cases crashes

Update: I checked with diferent versions of 4.2 and works fine until Godot 4.2 dev4. Before that Godot 4.2 dev5 and so on crashes. So the problem is in something on dev5 commits

@AThousandShips
Copy link
Member

Can you please try with 4.1.3 as well?

@Ekaitzsegurola
Copy link

Can you please try with 4.1.3 as well?

In 4.1.3 works fine

I am starting to thing it could have something to do with this

#85875 (comment)

And maybe old Tilemaps can crash for not containing something new for that improvements

My next move is to try to create a simple project with tilemap before 4.2 dev5 and see if crashes in dev5 and after

@Nualie You said the project was from start 4.2, but maybe 4.2 dev?

@AThousandShips
Copy link
Member

I will try to take a proper look at this in the next few days, I was investigating the original issue for some time but since it didn't have an MRP reproducing it reliably was impossible and therefore no fix was possible, this should help, I am 90% sure this is due to either some invalid copying of the SelfList, or some other memory corruption, either of which would break this as it would make the element no longer point to the correct list while still being seen as part of that list

I'd appreciate if someone who can reproduce this can test this PR, as it fixes one of the possible causes of this, if nothing else it narrows it down, and I will investigate it when I find the time:

@Nualie
Copy link

Nualie commented Dec 28, 2023

Can you please try with 4.1.3 as well?

In 4.1.3 works fine

I am starting to thing it could have something to do with this

#85875 (comment)

And maybe old Tilemaps can crash for not containing something new for that improvements

My next move is to try to create a simple project with tilemap before 4.2 dev5 and see if crashes in dev5 and after

@Nualie You said the project was from start 4.2, but maybe 4.2 dev?

nope, 4.2 mono stable @Ekaitzsegurola

@Ekaitzsegurola
Copy link

Ekaitzsegurola commented Dec 29, 2023

I will try to take a proper look at this in the next few days, I was investigating the original issue for some time but since it didn't have an MRP reproducing it reliably was impossible and therefore no fix was possible, this should help, I am 90% sure this is due to either some invalid copying of the SelfList, or some other memory corruption, either of which would break this as it would make the element no longer point to the correct list while still being seen as part of that list

I'd appreciate if someone who can reproduce this can test this PR, as it fixes one of the possible causes of this, if nothing else it narrows it down, and I will investigate it when I find the time:

* [[Core] Prevent copying of `SelfList` and `SelfList::List` #85180](https://github.com/godotengine/godot/pull/85180)

I compiled your Pull Request. Is over 4.2 RC2 right?

It does not work. I am not sure but seems to crash even faster

Same error in infinite loop

ERROR: Condition "p_elem->_root != this" is true. at: remove (./core/templates/self_list.h:80)

How can i compile for Mono C#?

@AThousandShips
Copy link
Member

AThousandShips commented Dec 29, 2023

It's on top of master, so not 4.2 rc2 just the latest master

Thank you for testing, then I'll get to looking at this when I can 🙂

@Ekaitzsegurola
Copy link

Ekaitzsegurola commented Dec 29, 2023

It's on top of master, so not 4.2 rc2 just the latest master

Thank you for testing, then I'll get to looking at this when I can 🙂

I have compiled two versions: One before this commit and another after. Before works fine, after versión crashes. So, should be here

Before commit (Fine): 31a7fd1
After commit (Crash): 8c1e282

8c1e282#diff-9bb6e79d028fa7d506aa846b3c2bbe33893107cb3d0c9e58f0a2cae1a3ca4234

If i can help in anything do not hesitate to ask

@baptr
Copy link
Contributor

baptr commented Jan 7, 2024

Here's a possibly slightly too small MRP. It seems harder to trigger quickly with small/simple tilemaps, but with some patience I can reliably hit it with this:
issue_86226.zip (assets credit)

Steps:

  1. Open main.tscn and select the TileMap node
  2. In the TileMap tab, it helps to look switch to the Patterns subtab (note there are two previews)
  3. Switch to the TileSet tab, Trees.png, Select tool, click on one of the big tree tiles
  4. Expand the Rendering section and click and drag in one of the coordinate spinners (I tend to use Texture Origin y or y sort origin)
  5. Wiggle your mouse for a few minutes to rapidly re-dirty that cell
    • Sometimes switching back to the TileMap tab and looking at the patterns has triggered it. Other times the previews don't redraw

Usually within ~30s, the editor should stop responding. If you have a terminal visible you should see the

ERROR: Condition "p_elem->_root != this" is true.
   at: remove (./core/templates/self_list.h:80)

spam until it fills up the message buffer and crashes

issue_86226

@AThousandShips
Copy link
Member

Thank you for those pointers, will investigate soon when I find the time

@baptr
Copy link
Contributor

baptr commented Jan 7, 2024

Probably because

tile_map->set_tileset(item.tile_set);

triggers the async _internal_update

tile_map_node->queue_internal_update();

via ~

tile_set->connect_changed(callable_mp(this, &TileMap::_tile_set_changed));

while
tile_map->set_pattern(0, Vector2(), item.pattern);
is iterating over the cells

@Nualie
Copy link

Nualie commented Jan 7, 2024

@AThousandShips @Nualie

In my case seems to be a wrong Pattern. When i try to draw that pattern it crashes with this message:

imagen

When i remove that pattern the file reduce size a lot and opening the editor again with that Pattern removed goes smoothly with no more crash for the moment. Maybe there is the problem

Pd: In Godot 4.2 dev4 (the last version without the famous crash lets me put that pattern with wrong tiles

imagen

this seems to be a different issue considering that the error message is completely different. You have invalid tiles displayed in your screenshot, and the error message says one of the tiles of the pattern just isn't defined.

baptr added a commit to baptr/godot that referenced this issue Jan 22, 2024
TilesEditorUtils calls tile_map->set_pattern from a thread (to refresh
tile pattern preview images). set_pattern sets each of the cells into the
temporary map, marking them dirty via set_cell.

This can race against the tree invoking the TileMapLayer's
internal_update, which proceses dirty.cell_list and eventually clears
it. If a cell's shared dirty entry ends up losing the race, clear can
get stuck in an infinite loop where remove refuses to change it because
the entry doesn't think it's a member of the list, but the list head
still points to it. This spams

ERROR: Condition "p_elem->_root != this" is true.
   at: remove (./core/templates/self_list.h:80)

And eventually leads to a crash when the error message buffer fills.

Guarding the list mutations avoids the race that sets up for this
failure, fixing godotengine#86226.
baptr added a commit to baptr/godot that referenced this issue Jan 22, 2024
@baptr
Copy link
Contributor

baptr commented Jan 22, 2024

There may be more general purpose fixes, but #87458 made sense to me and seems to prevent this

@AThousandShips
Copy link
Member

(please avoid referencing issues in commits, as you can see it badly pollutes the thread and makes it hard to follow)

@AThousandShips
Copy link
Member

Investigated and this particular issue is caused by the preview generation being run on a thread and causing race conditions, there is possibly a broader thread safety concern with TileMap due to some race conditions when the node is not in the tree which warrants their own investigation as well

@AThousandShips
Copy link
Member

To ensure more general thread safety I would suggest possibly not doing internal updates when not on the tree, this would make it possible to ensure thread safety, but will have to investigate further if this affects usability in general, but would probably be a separate PR unless there's no impact on the results as it'd break compat at least to some degree and this fix would be good to get for the editor crash in a future 4.2 version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment