sinbad / SPUD

Steve's Persistent Unreal Data library
MIT License
300 stars 44 forks source link

No longer crashes when exiting the game from a world partitioned level #52

Closed cyphusx closed 1 year ago

cyphusx commented 1 year ago

When the player quits to desktop from a world partitioned world, the levels start to receive the OnLevelHidden callback.

Midway through processing all of the levels, USpudSubsystem::Deinitialize() gets called, and then all GameInstance subsystems, including USpudSubsystem, are removed from the GameInstance.

However, the world continues to process the OnLevelHidden callbacks, but they are now not able to retrieve the USpudSubsystem in order to save the level state, and this causes a crash.

I've resolved this a number of ways - first, the OnLevelHidden and OnLevelShown methods now check for a valid USpudSubsystem, and throw an ensure with an explanation if it's not valid.

Secondly, when USpudSubsystem::Deinitialize() is called, I'm clearing out the list of monitored streaming levels, and manually calling OnLevelHidden on those that are still visible, so that their state is stored before the subsystem is destroyed.

sinbad commented 1 year ago

Thanks for this!

Q about the OnLevelHidden calls though: all this is going to do is store the level state in the active state in memory, once the system has fully shut down that state is just going to be discarded, so it's not really worth doing? Unless something could jump in at the very last minute and save it, but that's unlikely if we're already in Deinitialize. I think unsubbing from hidden/shown is all that should be done here rather than the save.

cyphusx commented 1 year ago

Ah, that is a good point, I'll sort out an updated version tomorrow - cheers!

cyphusx commented 1 year ago

Updated to no longer call OnLevelHidden during Deinitialize, and updated some spaces to be tabs.

sinbad commented 1 year ago

Awesome, thanks very much! All merged.