All Questions


Daniel Queiroz Porto

Index out of range error

I can't get this one to work at all, I keep getting an index out of range error on line

var byte: int = raw[idx]

I don't understand what is wrong, I've just spent more than an hour and a half trying to find relevant differences between your code and mine, or your scene and mine and just failed to find any.

If I clamp the index the code runs, but the effect is wrong and doesn't follow the mask at all.

Here is the github project if you can help me with this

It's the Dissolve2D.tscn scene inside experiments/dissolve folder.

I tried running the source project that comes with the course, and it works fine!

The biggest difference between the projects is that I'm using GLES2 as I'm exporting it for web, but I also tried changing to GLES3 and the CPUParticle2D to a Particle2D and copying your code, but I got the same error, so it must be something about the scene or project setup?

  • Razoric replied

    Hiya! Looks like ViewportTextures in GLES 2 only have 3 bytes of data for R, G and B by default and don't include one for alpha. As a result, the math should be changed to (y * width + x) * 3.

    I'll include a note about that in the tutorial as an update.

  • Daniel Queiroz Porto replied

    Wow thanks! I was just about to go back to it and try to find what I was doing wrong and this fixed it!