Facepunch / sbox-issues

175 stars 12 forks source link

Out of Game rendering update: using `SceneMap` in `GameMenu` create s&box crash #4023

Closed PolSpock closed 1 year ago

PolSpock commented 1 year ago

Describe the bug

Hi,

Since the Out-of-game rendering update, my GameMenu that embed a SceneMap loaded from asset.party package are constantly producing a s&box crash

I've been able to reproduce the issue on the sandbox game. Look down below to see the steps to reproduce

To Reproduce

1) Download https://github.com/Facepunch/sandbox 2) Replace the content of code/Menu/MainMenu.razor :

code/Menu/MainMenu.razor ``` @using Sandbox; @using Sandbox.UI; @using Sandbox.Menu.backgroundmap; @inherits RootPanel @implements Sandbox.Menu.IGameMenuPanel @namespace Sandbox.Menu hey ```

3) Create folder code/Menu/backgroundmap 4) Create BackgroundMap.razor:

BackgroundMap.razor ``` @using Sandbox.UI.Construct; @using Sandbox.UI; @namespace Sandbox.Menu.backgroundmap @attribute [StyleSheet] @inherits Panel @code { private static BackgroundMap Current; public BackgroundMap() { Current = this; } private ScenePanel scenePanel; private SceneWorld sceneWorld; public SceneMap SceneMap { get; set; } public override void OnHotloaded() { RefreshWorld(); } protected override void OnAfterTreeRender(bool firstTime) { if (firstTime) { RefreshWorld(); } } public async void RefreshWorld() { Log.Info("RefreshWorld"); // Cleanup scenePanel?.Delete(); sceneWorld?.Delete(); sceneWorld = new SceneWorld(); scenePanel = Add.ScenePanel(sceneWorld, Vector3.Zero, Rotation.Identity, 90); if (Package.TryParseIdent("roomfield.avatar_menu_map", out var parsed)) { Package package = await Package.FetchAsync(parsed.org + "." + parsed.package, false); if (package == null || package.PackageType != Package.Type.Map || package.Revision == null) { return; } string meta = package.GetMeta("PrimaryAsset"); await package.MountAsync(false); var map = ""; if (meta != null) { map = meta; } SceneMap = await SceneMap.CreateAsync(sceneWorld, map.Replace(".vmap", "")); } RefreshSceneCamera(); } private void RefreshSceneCamera() { Log.Info("RefreshSceneCamera"); scenePanel.World = sceneWorld; scenePanel.Camera.Position = new Vector3(-8f, -168f, 56f); scenePanel.Camera.Rotation = Rotation.From(new Angles(0, 90f, 0f)); scenePanel.Camera.FieldOfView = 90; scenePanel.Camera.Name = "PlayerScene"; } } ```

5) Create BackgroundMap.razor.scss:

BackgroundMap.razor.scss ``` BackgroundMap { position: absolute; flex-grow: 1; width: 100%; height: 100%; scenepanel { flex-grow: 1; } } ```

6) Start your s&box & sandbox game Normally you will see the roomfield.avatar_menu_map SceneMap and "hey" text 7) Start the game with buttons image

8) Quit the game once loaded: you will crash 9) However if you comment <BackgroundMap /> from the MainMenu.razor, you will not crash

Expected behavior

Using SceneMap in the GameMenu state must not result in s&box crash

Media/Files

No response

Additional context

No response

PolSpock commented 1 year ago

Hello, another issue with this issue : If your game embedded a SceneMap in your GameMenu, your s&box client will crash after client loading when the server launches a Sandbox.Game.ChangeLevel

PolSpock commented 12 months ago

https://github.com/sboxgame/issues/assets/5229571/7d087d55-d2d5-4dd7-b6b4-a9bfdd25e2d1

Hello, i would like to reopen the issue cause the crashing state is still there after a hotload, see my video above

(For the video i have reproduced the same step as explained in my "To reproduce" part)