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

twgl.createTexture does not call the callback if options.src is an html element #179

Open
alexkh opened this issue Feb 26, 2021 · 3 comments

Comments

@alexkh
Copy link

alexkh commented Feb 26, 2021

Greetings!

@greggman
Copy link
Owner

Is there a reason to call the callback if options.src is an element? It's not asynchronous.

@alexkh
Copy link
Author

alexkh commented Feb 26, 2021

In my code I wanted to be able to load image by url or from element, and once the texture is created call some code. So now to handle both cases I need to set a timeout to check if texture was loaded and it's a bit messy... It'd be nice if I specify a callback, the function would automatically become asynchronous in case that I rely on the callback and not having to process both asynchronous and synchronous cases. That'd make the interface more straightforward.

I did notice that simply calling the callback is not the best idea, because if the function is not asynchronous, the return value would not be set at the moment of calling the callback and the callback might rely on that return value being set...

It took me a while to figure out why my code stopped working after switching from url to html element.

@alexkh
Copy link
Author

alexkh commented Feb 26, 2021

one possible fix in function createTexture:

  setTextureFromElement(gl, tex, src, options);
  width = src.width;
  height = src.height;
  if(callback) {
    setTimeout(function() {callback(null, tex, src)}, 0);
  }

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

2 participants