mirror of
https://github.com/Facepunch/sbox-public.git
synced 2025-12-23 22:48:07 -05:00
Shutdown scene early (#3576)
* Destroy ActiveScene early during game shutdown * Don't call into native when deleting scenemaps
This commit is contained in:
@@ -210,7 +210,7 @@ public sealed partial class SceneMap : IValid
|
||||
if ( PVS.IsValid )
|
||||
{
|
||||
// don't destroy if another SceneWorld is using it
|
||||
if ( !SceneWorld.All.Where( x => x.IsValid() && x.native.GetPVS() == PVS ).Any() )
|
||||
if ( !SceneWorld.All.Any( x => x.ActivePVS == PVS ) )
|
||||
{
|
||||
g_pEnginePVSManager.DestroyPvs( PVS );
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public sealed partial class SceneWorld : IHandle
|
||||
internal HashSet<SceneObject> InternalSceneObjects { get; set; } = new();
|
||||
internal HashSet<SceneMap> InternalSceneMaps { get; set; } = new();
|
||||
internal HashSet<SceneSkybox3D> InternalSkyboxWorlds { get; set; } = new();
|
||||
internal IPVS ActivePVS { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of scene objects belonging to this scene world.
|
||||
@@ -100,6 +101,7 @@ public sealed partial class SceneWorld : IHandle
|
||||
|
||||
CSceneSystem.DestroyWorld( this );
|
||||
native = IntPtr.Zero;
|
||||
ActivePVS = default;
|
||||
}
|
||||
|
||||
internal void OnNativeInit( ISceneWorld ptr )
|
||||
@@ -111,6 +113,7 @@ public sealed partial class SceneWorld : IHandle
|
||||
internal void OnNativeDestroy()
|
||||
{
|
||||
native = IntPtr.Zero;
|
||||
ActivePVS = default;
|
||||
All.Remove( this );
|
||||
}
|
||||
|
||||
@@ -168,6 +171,7 @@ public sealed partial class SceneWorld : IHandle
|
||||
{
|
||||
//Log.Info( $"{this} - SET PVS from {sceneMap}" );
|
||||
native.SetPVS( sceneMap.PVS );
|
||||
ActivePVS = sceneMap.PVS;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,10 +186,14 @@ public sealed partial class SceneWorld : IHandle
|
||||
Log.Warning( "Couldn't remove sceneMap" );
|
||||
}
|
||||
|
||||
if ( native.GetPVS() == sceneMap.PVS )
|
||||
if ( ActivePVS == sceneMap.PVS )
|
||||
{
|
||||
if ( !native.IsNull )
|
||||
{
|
||||
native.SetPVS( default );
|
||||
}
|
||||
ActivePVS = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,9 @@ internal partial class GameInstance : IGameInstance
|
||||
|
||||
_packageAssembly = null;
|
||||
|
||||
// Tear down the active scene while content is still mounted so native handles remain valid during cleanup
|
||||
Game.Shutdown();
|
||||
|
||||
GlobalContext.Current.UISystem.Clear();
|
||||
|
||||
if ( activePackage != null && !Application.IsStandalone )
|
||||
@@ -123,8 +126,6 @@ internal partial class GameInstance : IGameInstance
|
||||
|
||||
GameInstanceDll.Current.Shutdown( this );
|
||||
|
||||
Game.Shutdown();
|
||||
|
||||
// If we were running a benchmark, leave the game
|
||||
if ( Application.IsBenchmark )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user