Skip to content

[FIX] Fix fog race condition crash on page reload#1696

Merged
willeastcott merged 2 commits intomainfrom
fog-fix
Jan 20, 2026
Merged

[FIX] Fix fog race condition crash on page reload#1696
willeastcott merged 2 commits intomainfrom
fog-fix

Conversation

@willeastcott
Copy link
Contributor

@willeastcott willeastcott commented Jan 20, 2026

Summary

  • Fix crash when viewport renders before scene settings are loaded
  • Simplify viewport initialization by removing unnecessary sceneSettingsObserver parameter passing

Details

Fixed a race condition that caused a TypeError: Cannot read properties of undefined (reading 'toUpperCase') crash. This occurred when:

  1. User has "Show Fog" enabled in Editor Settings
  2. Scene has fog type set to something other than "none"
  3. On page reload, the viewport renders before scene settings data arrives from the server
  4. sceneSettings.get('render.fog') returns undefined, which crashes the engine

Changes

  • Added nullish coalescing fallback (?? pc.FOG_NONE) when reading fog settings in viewport-application.ts and camera-preview.ts

  • Simplified ViewportApplication by calling editor.call('sceneSettings') directly instead of storing and passing sceneSettingsObserver through the constructor

  • I confirm I have read the contributing guidelines

@willeastcott willeastcott self-assigned this Jan 20, 2026
@willeastcott willeastcott added the bug Something isn't working label Jan 20, 2026
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 race condition crash that occurred when the viewport rendered before scene settings were loaded on page reload. The fix adds defensive null checks using nullish coalescing and optional chaining when reading fog settings, and simplifies the code by removing unnecessary parameter passing.

Changes:

  • Added nullish coalescing fallback (?? pc.FOG_NONE) with optional chaining for fog settings access in viewport-application.ts and camera-preview.ts
  • Removed unnecessary sceneSettingsObserver parameter passing from viewport.ts constructor
  • Replaced stored sceneSettingsObserver property with direct editor.call('sceneSettings') calls

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/editor/viewport/viewport.ts Removed sceneSettingsObserver variable and parameter passing to simplify initialization
src/editor/viewport/viewport-application.ts Added optional chaining and nullish coalescing for fog settings, removed sceneSettingsObserver property
src/editor/viewport/camera/camera-preview.ts Added nullish coalescing for fog settings fallback

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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@willeastcott willeastcott merged commit e6d36d5 into main Jan 20, 2026
3 checks passed
@willeastcott willeastcott deleted the fog-fix branch January 20, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants