mayognaise / aframe-gif-shader

A shader to display GIF for A-Frame VR.
https://mayognaise.github.io/aframe-gif-shader/basic
MIT License
107 stars 44 forks source link

[Resolved] Gif does not render (Offset overflows texture dimensions) #23

Open Snowirbix opened 1 year ago

Snowirbix commented 1 year ago

When using the shader with aframe > 1.3.0 9 times out of 10 I get the following errors: Firefox: WebGL warning: texSubImage: Offset+size must be <= the size of the existing specified image. Chrome: _INVALID_VALUE: Offset overflows texture dimensions.

The shader creates a canvas with dimensions 2x2 and then updates it. The issue is caused by the modification of the dimensions of the canvas. So my fix is to use the right canvas dimensions from the get go.

Replace these lines:

init: function init(data) {
  log('init', data);
  log(this.el.components);
  this.__cnv = document.createElement('canvas');
  this.__cnv.width = 2;
  this.__cnv.height = 2;
  this.__ctx = this.__cnv.getContext('2d');

with these:

init: function init(data) {
  log("init", data);
  log(this.el.components);
  var srcElement = document.querySelector(data.src);
  this.__cnv = document.createElement("canvas");
  this.__cnv.width = srcElement.width;
  this.__cnv.height = srcElement.height;
  this.__ctx = this.__cnv.getContext("2d");

Happy coding !