Skip to content

Commit a4cc01b

Browse files
authored
v3 issues (#630)
* Fix text node destroy race condition * Fix texture coordinate update flow * Guard against RTT texture creation while w/h dimension updates race condition
2 parents fedacf0 + 3ae5e2a commit a4cc01b

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/core/CoreNode.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
* limitations under the License.
1818
*/
1919

20-
import { describe, expect, it, vi } from 'vitest';
20+
import { describe, expect, it } from 'vitest';
2121
import { CoreNode, type CoreNodeProps, UpdateType } from './CoreNode.js';
2222
import { Stage } from './Stage.js';
23+
import { CoreRenderer } from './renderers/CoreRenderer.js';
2324
import { mock } from 'vitest-mock-extended';
2425
import { type TextureOptions } from './CoreTextureManager.js';
2526
import { createBound } from './lib/utils.js';
@@ -78,6 +79,7 @@ describe('set color()', () => {
7879
defaultTexture: {
7980
state: 'loaded',
8081
},
82+
renderer: mock<CoreRenderer>() as CoreRenderer,
8183
});
8284

8385
describe('set color()', () => {

src/core/CoreNode.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,12 @@ export class CoreNode extends EventEmitter {
16941694
const coords = this.renderCoords;
16951695
const texture = p.texture || this.stage.defaultTexture;
16961696

1697+
// There is a race condition where the texture can be null
1698+
// with RTT nodes. Adding this defensively to avoid errors.
1699+
if (texture && texture.state !== 'loaded') {
1700+
return;
1701+
}
1702+
16971703
renderer.addQuad({
16981704
width: p.w,
16991705
height: p.h,
@@ -1780,7 +1786,7 @@ export class CoreNode extends EventEmitter {
17801786

17811787
set w(value: number) {
17821788
if (this.props.w !== value) {
1783-
this.textureCoords = undefined;
1789+
this.updateTextureCoords = true;
17841790
this.props.w = value;
17851791
this.setUpdateType(UpdateType.Local);
17861792

@@ -1802,7 +1808,7 @@ export class CoreNode extends EventEmitter {
18021808

18031809
set h(value: number) {
18041810
if (this.props.h !== value) {
1805-
this.textureCoords = undefined;
1811+
this.updateTextureCoords = true;
18061812
this.props.h = value;
18071813
this.setUpdateType(UpdateType.Local);
18081814

@@ -2139,6 +2145,10 @@ export class CoreNode extends EventEmitter {
21392145
}
21402146

21412147
set zIndex(value: number) {
2148+
if (this.props.zIndex === value) {
2149+
return;
2150+
}
2151+
21422152
this.props.zIndex = value;
21432153
this.setUpdateType(UpdateType.CalculatedZIndex | UpdateType.Children);
21442154
for (let i = 0, length = this.children.length; i < length; i++) {

src/core/CoreTextNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps {
268268
}
269269

270270
override destroy(): void {
271-
if (this._waitingForFont === true) {
271+
if (this._waitingForFont === true && this.fontHandler) {
272272
this.fontHandler.stopWaitingForFont(this.textProps.fontFamily, this);
273273
}
274274

0 commit comments

Comments
 (0)