Fix scene stall and excessive memory usage caused by CReflectionProbe deserialization bugs #605
+19
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Overload was stalling and consuming excessive memory (up to 28GB) when creating new scenes or loading scenes containing reflection probes. This issue was reported in #602 and investigated through Tracy profiler captures which showed the deserialization process taking an abnormally long time.
Root Cause
The issue was caused by multiple bugs in
CReflectionProbe::OnDeserialize()
:1. Duplicate Resolution Deserialization
The
resolution
field was being deserialized twice:The duplicate deserialization could overwrite valid values with garbage data, leading to invalid resolution values being set.
2. Missing Resource Reallocation
When
m_resolution
orm_captureSpeed
changed during deserialization, GPU resources (framebuffers, cubemaps) were not reallocated to match the new configuration. This caused:The setter methods (
SetCubemapResolution()
,SetCaptureSpeed()
) properly handle resource reallocation, but direct deserialization bypassed this logic.3. No Validation
Deserialized resolution values weren't validated. Invalid values (zero or non-power-of-2) could be set without checks, potentially causing crashes or undefined behavior.
4. Assertion Bug
The power-of-2 assertion in
SetCubemapResolution()
had incorrect syntax:Solution
CReflectionProbe::OnDeserialize()
_AllocateResources()
is called to properly allocate GPU resourcesCReflectionProbe::SetCubemapResolution()
> 0
at the end of the power-of-2 checkScene::AddDefaultAtmosphere()
Impact
These changes ensure that:
Testing
While the project couldn't be compiled in the CI environment (Windows-only), the fixes follow established patterns in the codebase (similar to
SetCaptureSpeed()
) and address the specific issues identified through code analysis and profiler traces.Manual testing should verify:
Fixes #604
Fixes #602
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.