-
Notifications
You must be signed in to change notification settings - Fork 55
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
Error in noise_generator.gd when using ThreadedChunkLoader2D #126
Comments
Hi there @Ronzan! This is indeed because signals aren't thread-safe. Ideally there will be a second pass (by me, most likely) on a few of the generators to make sure such things are thread-safe out of the box. For now, wrap those signals with a lambda, then call_deferred them, similar to in the Heightmap generators:
It's not exactly clean looking, persay, but it is the best way to fix this issue based on what I've read in Godot's docs. |
Hi @cullumi |
Happy to help! :D After doing some stress-testing, it seems that a bunch of deferred calls to TileMap.set_cell() and TileMap.erase_cell() in TilemapGaeaRenderer's _draw_area method were being batched together and run all at the same time. The solution? Replace those deferred calls with thread_safe calls. This should help because now tile changes will be guaranteed to be paced out as they become ready; should smooth things out a bit. In TilemapGaeaRenderer, try changing the following lines from: tile_map.erase_cell.call_deferred( l, Vector2i(x, y))
(...)
tile_map.set_cell.call_deferred(
tile_info.tilemap_layer, tile, tile_info.source_id,
tile_info.atlas_coord, tile_info.alternative_tile
) to: tile_map.call_thread_safe("erase_cell", l, Vector2i(x, y))
(...)
tile_map.call_thread_safe("set_cell",
tile_info.tilemap_layer, tile, tile_info.source_id,
tile_info.atlas_coord, tile_info.alternative_tile
) Hopefully that helps with the lag spikes. (I'll likely be making PR with these changes tomorrow if someone else doesn't beat me to the punch; it's late and I gotta work tomorrow morning lol) |
Thanks again @cullumi Running the profiler, it looks like it is renderers and the chunkloader causing the spikes: Should I make an isolated project and try and reproduce? or record a clip? |
Fixed in #127 |
Hello
Not sure if I'm doing something wrong, but I get following error:
The setup is working, generating chunks as the player moves around - it lags a lot when chunks are generated though.
The setup looks like this:
I've tried to search a bit and found a few places that mentions signals not being thread-safe - but I really don't know since this is my first Godot test project :)
I can make a full repro if needed, just thought I would check here to see if I've done something obvious wrong.
/Ronzan
The text was updated successfully, but these errors were encountered: