Skip to content

Fix: Clarify Attributes property caching in SceneObject#96

Closed
PatrickJnr wants to merge 1 commit intoFacepunch:masterfrom
PatrickJnr:fix/sceneobject-attributes-caching
Closed

Fix: Clarify Attributes property caching in SceneObject#96
PatrickJnr wants to merge 1 commit intoFacepunch:masterfrom
PatrickJnr:fix/sceneobject-attributes-caching

Conversation

@PatrickJnr
Copy link
Copy Markdown
Contributor

Problem

The Attributes property had a FIXME about allocating CSceneObject::m_pExtraData even when only reading. Although the ??= operator cached the value, the behaviour wasn't explicit.

Solution

Changed to an explicit if (_attributes == null) check for clarity and removed the misleading FIXME comment.

Testing

The test file was removed before committing.
Verified that multiple accesses to Attributes return the same cached instance.

image

- Changed from null-coalescing operator to explicit null check
- Makes caching behavior more clear and maintainable
- Verified same RenderAttributes instance returned on multiple accesses
@chrisspieler
Copy link
Copy Markdown

Regarding the removed comment:

  • How did you determine that the comment was inaccurate?

Regarding the change to null checking:

  • Is the justification for this change that someone reading the source code of the engine might not know that a null-coalescing assignment evaluates to the new value of its left-hand side?

@PatrickJnr PatrickJnr closed this Dec 10, 2025
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.

2 participants