Skip to content

Fix a-sky losing material.side 'back' because of previous object recycling#5831

Open
vincentfretin wants to merge 4 commits into
aframevr:masterfrom
vincentfretin:a-sky-issue
Open

Fix a-sky losing material.side 'back' because of previous object recycling#5831
vincentfretin wants to merge 4 commits into
aframevr:masterfrom
vincentfretin:a-sky-issue

Conversation

@vincentfretin

Copy link
Copy Markdown
Contributor

This fixes the issue I had with the environment component supermedium/aframe-environment-component#89

Fix primitive default components clobbered by recycled component attrValue mergeComponentData merged the entity-defined value into a primitive's default/extra component data with utils.extend (Object.assign), which copies undefined-valued keys. A component's attrValue is a pooled object that keeps its keys (valued undefined) when recycled, so a reused attrValue like {side: undefined, ..., src: 'sky.webp'} would clobber the primitive defaults (e.g. a-sky's material side: back -> undefined -> material schema default 'front'). This made <a-sky material="src: ..."> created via createElement + setAttribute intermittently lose side/shader/minFilter depending on object-pool state.

Only merge in defined properties so stale recycled keys no longer overwrite the extra/default data.

@vincentfretin vincentfretin changed the title Fix a-sky losing material.side 'back' if unlucky Fix a-sky losing material.side 'back' because of previous object recycling Jun 13, 2026
vincentfretin and others added 3 commits June 13, 2026 18:27
utils.extend is Object.assign; called with a single argument it returns
that argument unchanged, so the wrapper did nothing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
parse() returns the original value unchanged when it is not a parseable
style string (already an object, or a string with no properties), so it
can return a string, not just an object.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…Value

mergeComponentData merged the entity-defined value into a primitive's
default/extra component data with utils.extend (Object.assign), which
copies undefined-valued keys. A component's attrValue is a pooled object
that keeps its keys (valued undefined) when recycled, so a reused
attrValue like {side: undefined, ..., src: 'sky.webp'} would clobber the
primitive defaults (e.g. a-sky's material side: back -> undefined ->
material schema default 'front'). This made <a-sky material="src: ...">
created via createElement + setAttribute intermittently lose
side/shader/minFilter depending on object-pool state.

Only merge in defined properties so stale recycled keys no longer
overwrite the extra/default data.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vincentfretin

Copy link
Copy Markdown
Contributor Author

I finally understood what was in my project that triggered it.
I have

        <a-entity
          geometry="primitive: sphere;
                    radius: 198;
                    segmentsWidth: 64;
                    segmentsHeight: 64;"
          material="color: #FFF; shader: flat; side: back; minFilter: linear"
          scale="-1 1 1"
          id="left-eye"
          visible="false"
        ></a-entity>

        <a-entity
          geometry="primitive: sphere;
                    radius: 198;
                    segmentsWidth: 64;
                    segmentsHeight: 64;"
          material="color: #FFF; shader: flat; side: back; minFilter: linear"
          scale="-1 1 1"
          id="right-eye"
          visible="false"
        ></a-entity>

then my close360 function is called that does

  const leftEyeSphere = document.querySelector("#left-eye");
  const rightEyeSphere = document.querySelector("#right-eye");
  if (leftEyeSphere && rightEyeSphere) {
    leftEyeSphere.object3D.visible = false;
    rightEyeSphere.object3D.visible = false;
    // dispose texture
    leftEyeSphere.removeAttribute("material");
    rightEyeSphere.removeAttribute("material");
  }

then my scene json loads that creates

{
  "element": "a-sky",
  "components": {
    "geometry": "",
    "material": "src: sky.webp",
  }
}

so I reproduced it in the test.

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