Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions src/core/CoreTextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,27 +239,23 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps {
// Handle Canvas renderer (uses ImageData)
if (textRendererType === 'canvas') {
if (result.imageData === undefined) {
this.emit('failed', {
type: 'text',
error: new Error(
'Canvas text rendering failed, no image data returned',
),
} satisfies NodeTextFailedPayload);
return;
}

this.texture = this.stage.txManager.createTexture('ImageTexture', {
premultiplyAlpha: true,
src: result.imageData as ImageData,
});
// It isn't renderable until the texture is loaded we have to set it to false here to avoid it
// being detected as a renderable default color node in the next frame
// it will be corrected once the texture is loaded
this.setRenderable(false);

if (this.renderState > CoreNodeRenderState.OutOfBounds) {
// We do want the texture to load immediately
this.texture.setRenderableOwner(this._id, true);
// Empty text returns no imageData — mark not renderable and continue
// to update dimensions (w=0, h=0) rather than emitting a failure.
this.setRenderable(false);
} else {
this.texture = this.stage.txManager.createTexture('ImageTexture', {
premultiplyAlpha: true,
src: result.imageData as ImageData,
});
// It isn't renderable until the texture is loaded we have to set it to false here to avoid it
// being detected as a renderable default color node in the next frame
// it will be corrected once the texture is loaded
this.setRenderable(false);

if (this.renderState > CoreNodeRenderState.OutOfBounds) {
// We do want the texture to load immediately
this.texture.setRenderableOwner(this._id, true);
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/core/CoreTextureManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ export class CoreTextureManager extends EventEmitter {
* @param immediate - Whether to prioritize the texture for immediate loading
*/
async loadTexture(texture: Texture, priority?: boolean): Promise<void> {
this.stage.txMemManager.removeFromOrphanedTextures(texture);

if (texture.type === TextureType.subTexture) {
// ignore subtextures - they get loaded through their parent
return;
Expand Down
27 changes: 0 additions & 27 deletions src/core/TextureMemoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export interface MemoryInfo {
export class TextureMemoryManager {
private memUsed = 0;
private loadedTextures: Set<Texture> = new Set();
private orphanedTextures: Set<Texture> = new Set();
private criticalThreshold: number = 124e6;
private targetThreshold: number = 0.5;
private cleanupInterval: number = 5000;
Expand Down Expand Up @@ -127,32 +126,6 @@ export class TextureMemoryManager {
this.updateSettings(settings);
}

/**
* Add a texture to the orphaned textures list
*
* @param texture - The texture to add to the orphaned textures list
*/
addToOrphanedTextures(texture: Texture) {
// if the texture is already in the orphaned textures list add it at the end
if (this.orphanedTextures.has(texture)) {
this.orphanedTextures.delete(texture);
}

// If the texture can be cleaned up, add it to the orphaned textures list
if (texture.preventCleanup === false) {
this.orphanedTextures.add(texture);
}
}

/**
* Remove a texture from the orphaned textures list
*
* @param texture - The texture to remove from the orphaned textures list
*/
removeFromOrphanedTextures(texture: Texture) {
this.orphanedTextures.delete(texture);
}

/**
* Set the memory usage of a texture
*
Expand Down
8 changes: 8 additions & 0 deletions src/core/text-rendering/CanvasTextRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ const renderText = (props: CoreTextNodeProps): TextRenderInfo => {
assertTruthy(canvas, 'Canvas is not initialized');
assertTruthy(context, 'Canvas context is not available');
assertTruthy(measureContext, 'Canvas measureContext is not available');

if (props.text.length === 0) {
return {
width: 0,
height: 0,
};
}

// Extract already normalized properties
const {
text,
Expand Down
Loading