Prevent immediate freeing of dynos model pools

This commit is contained in:
MysterD 2023-05-17 22:22:05 -07:00
parent 136ac0d84c
commit c126bf82b3

View file

@ -23,7 +23,6 @@ struct ModelInfo {
struct ScheduledFreePool { struct ScheduledFreePool {
struct DynamicPool* pool; struct DynamicPool* pool;
u32 timeout;
}; };
static struct DynamicPool* sModelPools[MODEL_POOL_MAX] = { 0 }; static struct DynamicPool* sModelPools[MODEL_POOL_MAX] = { 0 };
@ -171,7 +170,6 @@ void DynOS_Model_ClearPool(enum ModelPool aModelPool) {
// schedule pool to be freed // schedule pool to be freed
sPoolsToFree.push_back({ sPoolsToFree.push_back({
.pool = sModelPools[aModelPool], .pool = sModelPools[aModelPool],
.timeout = 30
}); });
// clear pointer // clear pointer
@ -203,12 +201,13 @@ void DynOS_Model_ClearPool(enum ModelPool aModelPool) {
} }
void DynOS_Model_Update() { void DynOS_Model_Update() {
for (auto it = sPoolsToFree.begin(); it != sPoolsToFree.end(); ) {
if (--it->timeout <= 0) { // only free a pool when we've scheduled at least 3
dynamic_pool_free_pool(it->pool); // this is required because the way that sm64 loads areas is actually insane
it = sPoolsToFree.erase(it); // if we free immediately, the camera graph node is incorrect on the star selection screen
} else { if (sPoolsToFree.size() <= 2) { return; }
it++;
} auto& it = sPoolsToFree[0];
} dynamic_pool_free_pool(it.pool);
sPoolsToFree.erase(sPoolsToFree.begin());
} }