-
Notifications
You must be signed in to change notification settings - Fork 110
Description
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 undefinedBecause 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