DataTexture image object is default

I am experiencing some weird behavior that i don’t understand.

I have:

this.propsTexture = this._createPropsTexture(size);
this.offsetTexture = this._createPropsTexture(size);

private _createPropsTexture(size: number) {
    return new DataTexture(
      new Uint8Array(size * size * 4),
      size,
      size,
      ...DEFAULT_PARAMS
    );
  }

Elsewhere

this._offsetsTexture.image.data[i4 + 1] = 5 //WORKS!!!!
const wth = this._offsetsTexture.image.data[i4 + 1]  //cant access  N of null 

When i log the image i see a width,height of 1 and data of null.

when i log the other texture created at the same time i see everything as i should

Your first line is accessing:

_offsetsTexture.image.data

the second line is accessing:

_offsetsTexture.data

I think only one of these is correct?

was a typo, wrote Image instead of .image :frowning:

yeah. :slight_smile: is the issue something else?

I meant, i didnt copy the code, i retyped the basics of it :smiley: im using typescript so it catches that.

Essentially:

console.log("props image", this._propsTexture.image);
console.log("offset image", this._offsetsTexture.image);
const debug = this._offsetTexture.image.data[i4 + 1]; // line 136 that throws
console.log("data array values", debug);

image

Here i am hovering over a breakpoint at 136, over the image object:
image

So… when you create a 1x1 pixel datatexture the image.data is null?
Is that the issue?

no, i never ever mention a 1x1 pixel texture, not sure how im getting it. Basically at line 135 i log foo.bar.image.data as Uint8 and then on the next i log foo.bar.image as {data:null} :face_with_spiral_eyes:

In the previous screenshots, 135 logs a data array, size 1024, line 136 logs (the same?) object as null and 1 :face_with_spiral_eyes:

geez it was a typo, i had a dummy offset texture i wasnt looking at the right one (but it wasnt the Image thing)

1 Like

The width and height of the datatexture shows 1. which is why I assumed you were creating a 1 pixel datatexture.

The way I’d debug these things is by putting a breakpoint on the line where you create the datatexture… and stepping into the constructor… inspecting (mouseovering) all the arguments to verify they contain what you expect…

When something looks impossible, it’s probably some other complexity biting you.

Otherwise… can you post a small reproduction of the issue in glitch?
Here’s a template you can remix and dump your stuff into: Glitch :・゚✧

Edit: Oh ok you solved it! Yaay!

1 Like