Skip to content

Conversation

@bawdeveloppement
Copy link

@bawdeveloppement bawdeveloppement commented Dec 26, 2025

Hello there is three commit, if you want to test, take first commit i added comments usefull as you can see callstacks.
The PR fix this issue : github.com/Facepunch/sbox-issues/issues/9749

debug-fix-game-preview.log

@bawdeveloppement
Copy link
Author

It fix this issue too : Facepunch/sbox-issues#9734

@bawdeveloppement
Copy link
Author

I'm available tomorrow to format and rebase.

…e wasnt switch to detected session scene tab
…e wasnt switch to detected session scene tab, without comments
…e wasnt switch to detected session scene tab, without comments
Copilot AI review requested due to automatic review settings January 13, 2026 04:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a game preview issue (GitHub issue #9749) by improving the state management and focus handling in the scene editor system.

Changes:

  • Added early return optimization in SceneEditorSession.MakeActive() to avoid redundant operations
  • Added focus management for scene dock when bringing to front
  • Updated viewport widget selection logic to prevent unnecessary updates

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
SceneViewportWidget.cs Modified condition to check if viewport is already selected before updating
SceneViewWidget.cs Added duplicate Current assignment (redundant) and reformatted early returns
SceneDock.cs Removed extra whitespace
SceneEditorSession.cs Added early return optimization and focus call in BringToFront
EditorScene.cs Added early return for non-prefab sessions and MakeActive call before play

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +164 to +166
if ( SceneEditorSession.Active is not PrefabEditorSession )
return SceneEditorSession.Active;

Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is redundant with the check at line 168. If SceneEditorSession.Active is not a PrefabEditorSession, then it cannot be a PrefabScene either (since PrefabEditorSession manages PrefabScene). The early return at line 164-165 makes the check at line 168 unnecessary for the same case, creating duplicate logic that reduces code clarity.

Suggested change
if ( SceneEditorSession.Active is not PrefabEditorSession )
return SceneEditorSession.Active;

Copilot uses AI. Check for mistakes.

var hasMouseFocus = hasMouseInput;
if ( IsFocused && SceneViewWidget.Current.IsValid() )
if ( IsFocused && SceneViewWidget.Current.LastSelectedViewportWidget != this && SceneViewWidget.Current.IsValid() )
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition checks are in the wrong order. The code checks SceneViewWidget.Current.LastSelectedViewportWidget before verifying SceneViewWidget.Current.IsValid(). If SceneViewWidget.Current is null or invalid, accessing .LastSelectedViewportWidget will throw a null reference exception. The IsValid() check should be performed first before accessing any properties of SceneViewWidget.Current.

Suggested change
if ( IsFocused && SceneViewWidget.Current.LastSelectedViewportWidget != this && SceneViewWidget.Current.IsValid() )
if ( IsFocused && SceneViewWidget.Current.IsValid() && SceneViewWidget.Current.LastSelectedViewportWidget != this )

Copilot uses AI. Check for mistakes.
Comment on lines +194 to +195


Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line added. This creates inconsistent whitespace formatting with the rest of the codebase.

Suggested change

Copilot uses AI. Check for mistakes.

if ( isActive )
{
// Log.Info("SceneViewWidget#Frame.L115 isActive");
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented-out debug code should be removed before merging. If this logging is needed for future debugging, consider using a proper logging level or conditional compilation flag instead of leaving commented code in the codebase.

Suggested change
// Log.Info("SceneViewWidget#Frame.L115 isActive");

Copilot uses AI. Check for mistakes.
Comment on lines +124 to +129
if ( isActive )
{
// Log.Info("SceneViewWidget#Frame.L115 isActive");
Current = this;
}

Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assignment Current = this is duplicated. This line sets Current = this when isActive is true, but the same assignment already occurs at line 108 under the same condition. The second assignment at line 127 is redundant and should be removed.

Suggested change
if ( isActive )
{
// Log.Info("SceneViewWidget#Frame.L115 isActive");
Current = this;
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant