[ts] Fix for NaN bounds

This is a temporary fix. Customer send reproduction sample. A slot has a mesh and corresponding deform. The number of vertices in the mesh is != the number of vertices in the deform, resulting in NaNs, which propagate to the bounds calculation of the web player. It is unclear how the mesh and deform can have a different number of vertices.
This commit is contained in:
badlogic 2021-04-06 14:11:55 +02:00
parent 3fdbf9a061
commit 748a03c7d7
16 changed files with 83 additions and 21 deletions

View File

@ -1402,7 +1402,7 @@ declare module spine.webgl {
static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL: boolean; static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL: boolean;
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap, useMipMaps?: boolean); constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap, useMipMaps?: boolean);
setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void; setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
static validateMagFilter(magFilter: TextureFilter): TextureFilter.Nearest | TextureFilter.Linear | TextureFilter.Linear; static validateMagFilter(magFilter: TextureFilter): TextureFilter.Nearest | TextureFilter.Linear;
setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void; setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
update(useMipMaps: boolean): void; update(useMipMaps: boolean): void;
restore(): void; restore(): void;

View File

@ -6,6 +6,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b); return extendStatics(d, b);
}; };
return function (d, b) { return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b); extendStatics(d, b);
function __() { this.constructor = d; } function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@ -4101,11 +4103,17 @@ var spine;
var mesh = attachment; var mesh = attachment;
verticesLength = mesh.worldVerticesLength; verticesLength = mesh.worldVerticesLength;
vertices = spine.Utils.setArraySize(temp, verticesLength, 0); vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
if (i == 43) {
console.log("WTF");
}
mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2); mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
} }
if (vertices != null) { if (vertices != null) {
for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) { for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) {
var x = vertices[ii], y = vertices[ii + 1]; var x = vertices[ii], y = vertices[ii + 1];
if (isNaN(x) || isNaN(y)) {
console.log("WTF");
}
minX = Math.min(minX, x); minX = Math.min(minX, x);
minY = Math.min(minY, y); minY = Math.min(minY, y);
maxX = Math.max(maxX, x); maxX = Math.max(maxX, x);
@ -12450,10 +12458,15 @@ var spine;
this.animationState.apply(this.skeleton); this.animationState.apply(this.skeleton);
this.skeleton.updateWorldTransform(); this.skeleton.updateWorldTransform();
this.skeleton.getBounds(offset, size); this.skeleton.getBounds(offset, size);
minX = Math.min(offset.x, minX); if (!isNaN(offset.x) && !isNaN(offset.y) && !isNaN(size.x) && !isNaN(size.y)) {
maxX = Math.max(offset.x + size.x, maxX); minX = Math.min(offset.x, minX);
minY = Math.min(offset.y, minY); maxX = Math.max(offset.x + size.x, maxX);
maxY = Math.max(offset.y + size.y, maxY); minY = Math.min(offset.y, minY);
maxY = Math.max(offset.y + size.y, maxY);
}
else {
console.log("Bounds of animation " + animationName + " are NaN");
}
} }
offset.x = minX; offset.x = minX;
offset.y = minY; offset.y = minY;

File diff suppressed because one or more lines are too long

View File

@ -6,6 +6,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b); return extendStatics(d, b);
}; };
return function (d, b) { return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b); extendStatics(d, b);
function __() { this.constructor = d; } function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@ -4101,11 +4103,17 @@ var spine;
var mesh = attachment; var mesh = attachment;
verticesLength = mesh.worldVerticesLength; verticesLength = mesh.worldVerticesLength;
vertices = spine.Utils.setArraySize(temp, verticesLength, 0); vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
if (i == 43) {
console.log("WTF");
}
mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2); mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
} }
if (vertices != null) { if (vertices != null) {
for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) { for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) {
var x = vertices[ii], y = vertices[ii + 1]; var x = vertices[ii], y = vertices[ii + 1];
if (isNaN(x) || isNaN(y)) {
console.log("WTF");
}
minX = Math.min(minX, x); minX = Math.min(minX, x);
minY = Math.min(minY, y); minY = Math.min(minY, y);
maxX = Math.max(maxX, x); maxX = Math.max(maxX, x);

File diff suppressed because one or more lines are too long

View File

@ -6,6 +6,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b); return extendStatics(d, b);
}; };
return function (d, b) { return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b); extendStatics(d, b);
function __() { this.constructor = d; } function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@ -4101,11 +4103,17 @@ var spine;
var mesh = attachment; var mesh = attachment;
verticesLength = mesh.worldVerticesLength; verticesLength = mesh.worldVerticesLength;
vertices = spine.Utils.setArraySize(temp, verticesLength, 0); vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
if (i == 43) {
console.log("WTF");
}
mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2); mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
} }
if (vertices != null) { if (vertices != null) {
for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) { for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) {
var x = vertices[ii], y = vertices[ii + 1]; var x = vertices[ii], y = vertices[ii + 1];
if (isNaN(x) || isNaN(y)) {
console.log("WTF");
}
minX = Math.min(minX, x); minX = Math.min(minX, x);
minY = Math.min(minY, y); minY = Math.min(minY, y);
maxX = Math.max(maxX, x); maxX = Math.max(maxX, x);

File diff suppressed because one or more lines are too long

View File

@ -1371,7 +1371,7 @@ declare module spine.webgl {
static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL: boolean; static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL: boolean;
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap, useMipMaps?: boolean); constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap, useMipMaps?: boolean);
setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void; setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
static validateMagFilter(magFilter: TextureFilter): TextureFilter.Nearest | TextureFilter.Linear | TextureFilter.Linear; static validateMagFilter(magFilter: TextureFilter): TextureFilter.Nearest | TextureFilter.Linear;
setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void; setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
update(useMipMaps: boolean): void; update(useMipMaps: boolean): void;
restore(): void; restore(): void;

View File

@ -6,6 +6,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b); return extendStatics(d, b);
}; };
return function (d, b) { return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b); extendStatics(d, b);
function __() { this.constructor = d; } function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@ -4101,11 +4103,17 @@ var spine;
var mesh = attachment; var mesh = attachment;
verticesLength = mesh.worldVerticesLength; verticesLength = mesh.worldVerticesLength;
vertices = spine.Utils.setArraySize(temp, verticesLength, 0); vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
if (i == 43) {
console.log("WTF");
}
mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2); mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
} }
if (vertices != null) { if (vertices != null) {
for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) { for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) {
var x = vertices[ii], y = vertices[ii + 1]; var x = vertices[ii], y = vertices[ii + 1];
if (isNaN(x) || isNaN(y)) {
console.log("WTF");
}
minX = Math.min(minX, x); minX = Math.min(minX, x);
minY = Math.min(minY, y); minY = Math.min(minY, y);
maxX = Math.max(maxX, x); maxX = Math.max(maxX, x);
@ -11761,10 +11769,15 @@ var spine;
this.animationState.apply(this.skeleton); this.animationState.apply(this.skeleton);
this.skeleton.updateWorldTransform(); this.skeleton.updateWorldTransform();
this.skeleton.getBounds(offset, size); this.skeleton.getBounds(offset, size);
minX = Math.min(offset.x, minX); if (!isNaN(offset.x) && !isNaN(offset.y) && !isNaN(size.x) && !isNaN(size.y)) {
maxX = Math.max(offset.x + size.x, maxX); minX = Math.min(offset.x, minX);
minY = Math.min(offset.y, minY); maxX = Math.max(offset.x + size.x, maxX);
maxY = Math.max(offset.y + size.y, maxY); minY = Math.min(offset.y, minY);
maxY = Math.max(offset.y + size.y, maxY);
}
else {
console.log("Bounds of animation " + animationName + " are NaN");
}
} }
offset.x = minX; offset.x = minX;
offset.y = minY; offset.y = minY;

File diff suppressed because one or more lines are too long

View File

@ -6,6 +6,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b); return extendStatics(d, b);
}; };
return function (d, b) { return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b); extendStatics(d, b);
function __() { this.constructor = d; } function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@ -4101,11 +4103,17 @@ var spine;
var mesh = attachment; var mesh = attachment;
verticesLength = mesh.worldVerticesLength; verticesLength = mesh.worldVerticesLength;
vertices = spine.Utils.setArraySize(temp, verticesLength, 0); vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
if (i == 43) {
console.log("WTF");
}
mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2); mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
} }
if (vertices != null) { if (vertices != null) {
for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) { for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) {
var x = vertices[ii], y = vertices[ii + 1]; var x = vertices[ii], y = vertices[ii + 1];
if (isNaN(x) || isNaN(y)) {
console.log("WTF");
}
minX = Math.min(minX, x); minX = Math.min(minX, x);
minY = Math.min(minY, y); minY = Math.min(minY, y);
maxX = Math.max(maxX, x); maxX = Math.max(maxX, x);

File diff suppressed because one or more lines are too long

View File

@ -1371,7 +1371,7 @@ declare module spine.webgl {
static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL: boolean; static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL: boolean;
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap, useMipMaps?: boolean); constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap, useMipMaps?: boolean);
setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void; setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
static validateMagFilter(magFilter: TextureFilter): TextureFilter.Nearest | TextureFilter.Linear | TextureFilter.Linear; static validateMagFilter(magFilter: TextureFilter): TextureFilter.Nearest | TextureFilter.Linear;
setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void; setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
update(useMipMaps: boolean): void; update(useMipMaps: boolean): void;
restore(): void; restore(): void;

View File

@ -6,6 +6,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b); return extendStatics(d, b);
}; };
return function (d, b) { return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b); extendStatics(d, b);
function __() { this.constructor = d; } function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@ -4101,11 +4103,17 @@ var spine;
var mesh = attachment; var mesh = attachment;
verticesLength = mesh.worldVerticesLength; verticesLength = mesh.worldVerticesLength;
vertices = spine.Utils.setArraySize(temp, verticesLength, 0); vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
if (i == 43) {
console.log("WTF");
}
mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2); mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
} }
if (vertices != null) { if (vertices != null) {
for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) { for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) {
var x = vertices[ii], y = vertices[ii + 1]; var x = vertices[ii], y = vertices[ii + 1];
if (isNaN(x) || isNaN(y)) {
console.log("WTF");
}
minX = Math.min(minX, x); minX = Math.min(minX, x);
minY = Math.min(minY, y); minY = Math.min(minY, y);
maxX = Math.max(maxX, x); maxX = Math.max(maxX, x);

File diff suppressed because one or more lines are too long

View File

@ -1216,10 +1216,14 @@ module spine {
this.skeleton.updateWorldTransform(); this.skeleton.updateWorldTransform();
this.skeleton.getBounds(offset, size); this.skeleton.getBounds(offset, size);
minX = Math.min(offset.x, minX); if (!isNaN(offset.x) && !isNaN(offset.y) && !isNaN(size.x) && !isNaN(size.y)) {
maxX = Math.max(offset.x + size.x, maxX); minX = Math.min(offset.x, minX);
minY = Math.min(offset.y, minY); maxX = Math.max(offset.x + size.x, maxX);
maxY = Math.max(offset.y + size.y, maxY); minY = Math.min(offset.y, minY);
maxY = Math.max(offset.y + size.y, maxY);
} else {
console.log("Bounds of animation " + animationName + " are NaN");
}
} }
offset.x = minX; offset.x = minX;