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

Fix call queue problems when loading TileSet #89493

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented Mar 14, 2024

When TileSet is being loaded, it will load every TileSetAtlasSource and it will emit changed signal for every tile and tile property. The signal is connected to _queue_update_padded_texture(), which doesn't have any safeguard against multiple calls, which means that it did a deferred call every time. So for my tileset with 40+ sources, 50+ tiles each that's like... 2000 deferred calls.

The fix in this PR is twofold:

  • it adds a safeguard in _queue_update_padded_texture() to prevent multiple deferred calls
  • it prevents redundant changed emissions while the TileSet is being loaded

Fixes the memory problem in #87593, effectively resolving the issue, as the project can load (albeit it's still extremely slow). The problem was that the deferred calls would build up and never get flushed, because many scenes were loaded one after another and the TileSet was repeatedly freed and loaded again (which is also why it takes so long). I have ~500 scenes that use this TileSet, so if you do the maths, it's obvious why the queue couldn't hold it.

Unfortunately it still results in some deferred calls that will very slowly clog up message queue, but since this makes like 100x less of them, it's much less likely to run out of memory. Not sure how to prevent it completely; we could maybe remove deferred call from queue manually by the TileSetAtlasSource if it's being deleted, but MessageQueue has no method for that AFAIK.

@KoBeWi KoBeWi added this to the 4.3 milestone Mar 14, 2024
@KoBeWi KoBeWi requested a review from groud March 14, 2024 20:25
Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, makes sense

@akien-mga akien-mga merged commit 0175be8 into godotengine:master Mar 14, 2024
16 checks passed
@KoBeWi KoBeWi deleted the just_download_more_ram branch March 14, 2024 21:37
@akien-mga
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants