Skip to content

Conversation

@Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Aug 26, 2025

Related issue: #31747 (comment)

Description

Fixes the dispose logic in the Sampler binding class.

* @type {function}
* @private
*/
this._onDisposeTexture = () => {
Copy link
Collaborator Author

@Mugen87 Mugen87 Aug 26, 2025

Choose a reason for hiding this comment

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

_onDisposeTexture() is cloned like all other properties. Because EventListener does not let you assign the same listener more than once, only the first dispose works. It has to be inlined in the setter of texture to make it work.

// TODO: Find better solution, see #31747

clonedSampler._texture = null;
clonedSampler.texture = this.texture;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An explicit call of the texture setter is required so cloned instances have proper dispose event listeners.

@github-actions
Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 338.91
79.11
338.91
79.11
+0 B
+0 B
WebGPU 578.16
159.25
578.22
159.27
+65 B
+18 B
WebGPU Nodes 576.76
159.01
576.83
159.03
+65 B
+18 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 470.78
113.9
470.78
113.9
+0 B
+0 B
WebGPU 648.69
175.28
648.76
175.3
+65 B
+18 B
WebGPU Nodes 602.79
164.41
602.85
164.42
+65 B
+19 B

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Aug 26, 2025

For r181, I think it's better to get rid of Object.assign() in Binding.clone(). Instead, we should implement the clone like for Object3D and then provide copy methods in all binding classes to control which properties should be copied. In this way, the code is more predictable.

@Mugen87 Mugen87 added this to the r180 milestone Aug 26, 2025
@sunag sunag merged commit 1686350 into mrdoob:dev Aug 26, 2025
13 of 14 checks passed
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