Add method to call for shutting down the ResourceManager thread pool #815
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a method in
ResourceManager
to allow for setting up a thread pool shutdown to prevent crashes when exiting while still loading assets. I have a wait time of 2 seconds here between pausing and purging to prevent deadlocks, more than that is unnecessary (especially if it's only for resource threads, as I think it should be). Unfortunately, because of the way shutdowns work, this has to be called manually from the port before nullingContext
. This is demonstrated in the asset preload PR: HarbourMasters/Shipwright#4652The reasoning for this PR is that I needed to be able to shut down the resource thread pool because of the way preloading would queue up a lot of loads at the start, and would crash if you tried to exit while in the opening sequence. This does not do any of the work of exposing the
ResourceManager
thread pool because there's still some ambiguity around the scope of that work (should only be used for non-critical tasks in my opinion; no save or config writing). The reason I needed to do it on the preload PR is because I couldn't get the crash to happen on latest develop. It's easiest to recreate with the 4K Reloaded pack. To let it trigger, comment the lineOTRGlobals::Instance->context->GetResourceManager()->ShutDownThreadPool();
in OTRGlobals (should be line 1248), and close the program as soon as you see the Nintendo logo. Uncomment it to see it not crash under the same circumstances. I think it still happens in release mode, but you'll get the stack trace in debug in VS.