ImmersiveRPG / GodotAsyncLoader

A Godot plugin to load, instance, and add scenes asynchronously using a background thread.
https://godotengine.org/asset-library/asset/1376
MIT License
38 stars 5 forks source link

Add a way to remove scenes from cache? #7

Open d-eisenga opened 2 years ago

d-eisenga commented 2 years ago

I was looking at SceneLoader.gd, specifically the _get_cached_scene function, and it looks like scenes never get removed from the _scenes cache. It looks like the cache just going to grow and grow while the game runs, using ever more memory. Some way to remove scenes from the cache will probably be needed for larger games.

workhorsy commented 2 years ago

I'll have to look into this more. I'm pretty sure that PackedScene is reference counted, and will get auto freed when there is nothing else using it.

d-eisenga commented 2 years ago

I'd assume if it's a value in a dictionary that would be considered a reference, but I admit I don't know much about Godot memory management.

workhorsy commented 2 years ago

For reference see ResourceCache: https://github.com/godotengine/godot/blob/3.5/core/io/resource_loader.cpp https://github.com/godotengine/godot/blob/3.5/core/io/resource_loader.h

https://docs.godotengine.org/en/3.5/tutorials/scripting/resources.html#freeing-resources

unicornlox commented 1 year ago

Is this problem solved? Can you write if it is solved?

workhorsy commented 1 year ago

Hey @mrParabol . Unfortunately I ran into a design flaws with the current code. I'm working on a partial re write that should solve these problems. I've just been super busy with real world stuff. So I haven't had as much time to work on improving things. Hopefully I will have more time soon.

unicornlox commented 1 year ago

hello @workhorsy Thank you for your answer. I understand you. In fact, if you explain why the added scene is not deleted or stayed in Cache, I can continue my way. I delete the added scene from the stage tree, but when I switch to different stage, the scene I deleted is added again. I am making a game and I used your plug -in in my game, but I cannot release my game with this problem. I used this plug -in in many different places, and I can't go back. If you can give a clue to prevent my efforts from going to waste, I will be grateful to you.

workhorsy commented 1 year ago

Hi @mrParabol . It sounds like you are talking about 2 different bugs. The cache only loads and stores a PackedScene. Those PackedScene resources are then cached. Instances of those PackedScenes are not cached. The instances are then added to the scene tree.

I think this may be a different bug. Can you show the code where you are using the plugin to add and remove to the scene tree?

Thanks