Skip to content

Draw function crashing because of undefined texture #521

@RuiTavaresSky

Description

@RuiTavaresSky

Issue context:
Version: 2.8.1

Currently when we have our project running in canvas mode we noticed that by reaching the memory pressure limit the stage.gc() is called to free up memory so that the app doesn't crash on the device. But sometimes what can happen is we free up a texture but the draw function is called and crashes here:

/core/src/renderer/c2d/shaders/DefaultShader.mjs

const sourceW = (stc ? 1 : (vc._brx - vc._ulx)) * tx.w; // tx is undefined

Because at that point the texture doesn't exist. We are able to prevent this by either preventing the texture and element to be added to the CoreQuadList (in CoreRenderState > addQuad) or by preventing from doing the draw function when the texture doesn't exist.

/core/src/tree/core/CoreRenderState.mjs

if (!nativeTexture) {
  const element = elementCore.element;
  let elementPath;
  
  if(element) {
    const ancestors = [];
    let current = element;
    do {
      ancestors.unshift(current);
    } while ((current = current.parent));

    elementPath = ancestors.map((element) => `[${element.constructor.name}]`).join(' > ');
  }

  logger.warn(`[Lightning][RenderState] nativeTexture is null - ${elementPath}`);

  this.stage.gc(true);
  return;
}

this.quads.quadTextures.push(nativeTexture);
this.quads.quadElements.push(elementCore);

this._quadOperation.length++;

this.renderer.addQuad(this, this.quads, this.length - 1);

OR

try / catch on method draw in /core/src/renderer/c2d/shaders/DefaultShader.mjs

We know that this is not an issue for webgl, since the logic for the draw function actually accepts the possibility of the texture being null

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions