Closed whatislostinthemines closed 1 month ago
Good catch. I see two different ways to handle that.
Either, I move the unload_bank
call to FmodBank's destructor (instead of BankLoader::exit_tree) and change the cache so the reference in it doesn't increase the counter, that way the bank will be unloaded only when the reference dies.
Or I change FmodBank to a regular Godot object with manual memory management and keep an internal counter in the cache that will increment/decrement with each call to load/unload-bank
.
The way FmodBankLoaders work currently, banks are loaded from bank_paths on tree enter, and unloaded on tree exit. This is handled with calls to FmodServer.
However, while the FmodBank class is set up to use godot's RefCounted class, this is never actually used. The check in FmodServer to avoid calling add_bank when the bank is already loaded keeps the bank's reference counter from being updated.
As a result, if multiple BankLoaders who all have some bank A are in a tree at the same time and one is released, that bank A will be invalid in the remaining and still active BankLoaders, without actually updating their bank_paths.