pixijs / pixi-projection

MIT License
190 stars 34 forks source link

Mesh2d vertexData2d undefined #73

Closed amikko92 closed 4 years ago

amikko92 commented 4 years ago

Occasionally I run into a crash bug when playing spine animations. The error log reads "Cannot read property 'length' of undefined" and points to line 65 in Mesh2d. The code there looks like this:

if (this.vertexData2d.length  !== vertices.length * 3 / 2)
{
    this.vertexData2d = new Float32Array(vertices.length * 3);
}

Checking in the debugger reveals that vertexData2d is indeed undefined. vertices on the other hand is correctly populated with vertex data.

What I find odd is how vertexData2d is supposed to be defined. The class initializes it to null and it's being assigned after the if-check that causes the crash. Unless it's assigned from somewhere outside. I haven't checked the entire code base.

I tried modifying the crash site to check for undefined:

if (this.vertexData2d === undefined || this.vertexData2d.length !== vertices.length * 3 / 2)
{
    this.vertexData2d = new Float32Array(vertices.length * 3);
}

Checking for undefined causes my animations to play as intended. However, I'm not 100 percent sure it doesn't produce some less obvious side effect.

Would it be correct to check for undefined as described?

ivanpopelyshev commented 4 years ago

oh !@#$ yes, make PR for it, but use if (this.vertexData2D || ...) because I like null's too :)

amikko92 commented 4 years ago

Alright, will do!

amikko92 commented 4 years ago

PR is open. I altered your suggestion to if (!this.vertexData2D ||.... I assume it is what you meant to type. Otherwise it won't evaluate to true for null and undefined. https://github.com/pixijs/pixi-projection/pull/74

amikko92 commented 4 years ago

With the release of version 0.3.12, my issue has been solved. Thank you for such a quick response.