I’m creating a game/game engine with procedurally generated environments - as part of that system all rooms/structures also have a reverb zone and unique sound geometry. When the player moves old structures are dynamically removed and new structures are built.
I have a queue of ReverbZones (which have geometry ptrs as a member) to be deleted so I can control when the memory is released. On rare occasions (I maybe get this bug every few hours of normal player movement) when geometry->release() is called the entire program will hang for an indefinite amount of time. I don’t get an FMOD_RESULT back from the call as the main thread is blocked/frozen somewhere in FMOD::Geometry*->release(). I have tried ensuring that the geometry cleanup is happening strictly before all other parts of FMOD updating, and also I have tried doing it strictly after - but it seems to make no difference. I was thinking perhaps geometry is trying to be released twice somehow but this is not possible as I eval if its nullptr and set it to nullptr after release.
Would appreciate any advice on this - its a hard bug to replicate but quite a nasty one since it causes the entire program to hang. At this point I’m considering maybe multi-threading the delete/release process just so I can ensure main thread is not blocked.
I think I have solve the issue.
First I tried running the garbage collection in async and also running some of the other FMOD tasks in async in order to have a timeout where I could determine where the threads had hung or been blocked and restart them but ultimately this was more of a crude band-aid than an actual solution.
Ultimately what I did was forced FMOD (studio) to run synchronously via using the FMOD_STUDIO_INIT_SYNCHRONOUS_UPDATE init flag, and then I also ensured that all garbage collection (deletion of older reverb zones and releasing the geometry) was done all at the same time rather than “on demand” - I did this using a simple queue of reverb zones to delete which is evaluated at a set point in my Sound Manager update function. After testing for 80 mins straight I did not come across any main thread blocks or hangs from geometry release, so I think it is safe to say that the bug was fixed.
Essentially it was due to me deleting things at the wrong time while they where in use by FMOD tasks/processes running in async.
Thanks for this follow up, I had your post pinned at the time for myself to investigate but the original post made me think reproducing would be difficult. I will look into reverb zones/geometry objects some more if they can be protected more like we do with other objects. ie make it possible to call functions on invalid handles and return FMOD_ERR_INVALID_HANDLE instead of crasihng.