Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw function crashing because of undefined texture #521

Open
RuiTavaresSky opened this issue Dec 19, 2023 · 4 comments
Open

Draw function crashing because of undefined texture #521

RuiTavaresSky opened this issue Dec 19, 2023 · 4 comments
Assignees

Comments

@RuiTavaresSky
Copy link

RuiTavaresSky commented Dec 19, 2023

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

@jorge-graca-sky
Copy link
Contributor

Still happens even after the #529 fix.

@wouterlucas
Copy link
Contributor

Thanks for raising this - in my first glance of this I'd opt for not adding it to the Quad list, however that would also negatively affect the WebGL path by adding extra logic (also I wouldn't call .gc() at the bottom there).

A Try/Catch might be a local Canvas impacted only path without introducing anything new to the WebGL side of things.

Let me study this a little more. And tagging @erikhaandrikman because I'm going to give him a call about this 😆

@wouterlucas
Copy link
Contributor

wouterlucas commented Sep 4, 2024

Spoke to Erik - going to look into adding a if check to bail out and see if there are any negative side effects, per Erik a Try/Catch might be an expensive chain to add for something that gets called so frequently.

Drukolia is going to have a look (for some reason I can't tag him here).

@Drulokia Drulokia self-assigned this Sep 4, 2024
@Drulokia
Copy link
Contributor

Cannot reproduce this from happening. Tried several ways, always when GC accurs when it goes through the Draw function in
/core/src/renderer/c2d/shaders/DefaultShader.mjs

the tx and the others are not undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants