Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix: use INVALID_TEXTURE as default sprite texture to prevent texture conflicts

esengine135695fad676
diff --git a/editor/src/scene/EditorSceneManager.ts b/editor/src/scene/EditorSceneManager.ts
index 41ef18806..7289d6b2e 100644
--- a/editor/src/scene/EditorSceneManager.ts
+++ b/editor/src/scene/EditorSceneManager.ts
@@ -9,6 +9,7 @@ import {
loadComponent,
LocalTransform,
Sprite,
+ INVALID_TEXTURE,
TextRenderer,
TextAlign,
TextVerticalAlign,
@@ -343,21 +344,21 @@ export class EditorSceneManager {
}
private async syncSprite(entity: Entity, data: any, entityId: number): Promise<void> {
- let textureHandle = 0;
+ let textureHandle = INVALID_TEXTURE as number;
let materialHandle = 0;
getDependencyGraph().clearEntity(entityId);
this.assetServer_.releaseMaterialInstance(entityId);
const texturePath = data.texture;
- if (texturePath) {
+ if (texturePath && typeof texturePath === 'string') {
const info = await this.assetServer_.loadTexture(texturePath);
textureHandle = info.handle;
getDependencyGraph().registerUsage(texturePath, entityId);
}
const materialPath = data.material;
- if (materialPath) {
+ if (materialPath && typeof materialPath === 'string') {
try {
const loaded = await this.assetServer_.loadMaterial(materialPath);
const overrides = data.materialOverrides;
@@ -451,7 +452,7 @@ export class EditorSceneManager {
let materialHandle = 0;
const materialPath = data.material;
- if (materialPath) {
+ if (materialPath && typeof materialPath === 'string') {
try {
const loaded = await this.assetServer_.loadMaterial(materialPath);
materialHandle = loaded.handle;
diff --git a/sdk/src/component.ts b/sdk/src/component.ts
index 45f5ce058..fdcecf278 100644
--- a/sdk/src/component.ts
+++ b/sdk/src/component.ts
@@ -3,7 +3,7 @@
* @brief Component definition and builtin components
*/
-import { Entity, Vec2, Vec3, Vec4, Quat } from './types';
+import { Entity, Vec2, Vec3, Vec4, Quat, INVALID_TEXTURE } from './types';
// =============================================================================
// Component Definition
@@ -185,7 +185,7 @@ export const WorldTransform = defineBuiltin<WorldTransformData>('WorldTransform'
});
export const Sprite = defineBuiltin<SpriteData>('Sprite', {
- texture: 0,
+ texture: INVALID_TEXTURE,
color: { x: 1, y: 1, z: 1, w: 1 },
size: { x: 32, y: 32 },
uvOffset: { x: 0, y: 0 },
diff --git a/sdk/src/ui/TextPlugin.ts b/sdk/src/ui/TextPlugin.ts
index eb7c0ee9c..0e96d1939 100644
--- a/sdk/src/ui/TextPlugin.ts
+++ b/sdk/src/ui/TextPlugin.ts
@@ -4,6 +4,7 @@
*/
import type { App, Plugin } from '../app';
+import { INVALID_TEXTURE } from '../types';
import { defineSystem, Schedule } from '../system';
import { Sprite, type SpriteData } from '../component';
import { Text, type TextData } from './text';
@@ -36,7 +37,7 @@ export class TextPlugin implements Plugin {
if (!world.has(entity, Sprite)) {
world.insert(entity, Sprite, {
- texture: 0,
+ texture: INVALID_TEXTURE,
size: { x: 0, y: 0 },
color: { x: 1, y: 1, z: 1, w: 1 },
anchor: { x: 0.5, y: 0.5 },