[libgdx] Wrap System.arraycopy for exceptions with more context.

This commit is contained in:
NathanSweet 2019-06-11 11:17:34 +02:00
parent 28862c94bc
commit ad6ed0911c
9 changed files with 47 additions and 17 deletions

View File

@ -31,6 +31,7 @@ package com.esotericsoftware.spine;
import static com.esotericsoftware.spine.Animation.MixBlend.*;
import static com.esotericsoftware.spine.Animation.MixDirection.*;
import static com.esotericsoftware.spine.utils.SpineUtils.*;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.MathUtils;
@ -1067,7 +1068,7 @@ public class Animation {
}
} else {
// Vertex positions or deform offsets, no alpha.
System.arraycopy(lastVertices, 0, deform, 0, vertexCount);
arraycopy(lastVertices, 0, deform, 0, vertexCount);
}
} else {
switch (blend) {
@ -1299,13 +1300,13 @@ public class Animation {
Array<Slot> drawOrder = skeleton.drawOrder;
Array<Slot> slots = skeleton.slots;
if (direction == out && blend == setup) {
System.arraycopy(slots.items, 0, drawOrder.items, 0, slots.size);
arraycopy(slots.items, 0, drawOrder.items, 0, slots.size);
return;
}
float[] frames = this.frames;
if (time < frames[0]) { // Time is before first frame.
if (blend == setup || blend == first) System.arraycopy(slots.items, 0, drawOrder.items, 0, slots.size);
if (blend == setup || blend == first) arraycopy(slots.items, 0, drawOrder.items, 0, slots.size);
return;
}
@ -1317,7 +1318,7 @@ public class Animation {
int[] drawOrderToSetupIndex = drawOrders[frame];
if (drawOrderToSetupIndex == null)
System.arraycopy(slots.items, 0, drawOrder.items, 0, slots.size);
arraycopy(slots.items, 0, drawOrder.items, 0, slots.size);
else {
for (int i = 0, n = drawOrderToSetupIndex.length; i < n; i++)
drawOrder.set(i, slots.get(drawOrderToSetupIndex[i]));

View File

@ -448,7 +448,7 @@ public class Skeleton {
/** Sets the slots and draw order to their setup pose values. */
public void setSlotsToSetupPose () {
Array<Slot> slots = this.slots;
System.arraycopy(slots.items, 0, drawOrder.items, 0, slots.size);
arraycopy(slots.items, 0, drawOrder.items, 0, slots.size);
for (int i = 0, n = slots.size; i < n; i++)
slots.get(i).setToSetupPose();
}

View File

@ -29,6 +29,8 @@
package com.esotericsoftware.spine;
import static com.esotericsoftware.spine.utils.SpineUtils.*;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
@ -38,6 +40,7 @@ import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.utils.JsonReader;
import com.badlogic.gdx.utils.JsonValue;
import com.badlogic.gdx.utils.SerializationException;
import com.esotericsoftware.spine.Animation.AttachmentTimeline;
import com.esotericsoftware.spine.Animation.ColorTimeline;
import com.esotericsoftware.spine.Animation.CurveTimeline;
@ -702,7 +705,7 @@ public class SkeletonJson {
else {
deform = new float[deformLength];
int start = valueMap.getInt("offset", 0);
System.arraycopy(verticesValue.asFloatArray(), 0, deform, start, verticesValue.size);
arraycopy(verticesValue.asFloatArray(), 0, deform, start, verticesValue.size);
if (scale != 1) {
for (int i = start, n = i + verticesValue.size; i < n; i++)
deform[i] *= scale;

View File

@ -29,6 +29,8 @@
package com.esotericsoftware.spine.attachments;
import static com.esotericsoftware.spine.utils.SpineUtils.*;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
@ -242,17 +244,17 @@ public class MeshAttachment extends VertexAttachment {
copyTo(copy);
copy.regionUVs = new float[regionUVs.length];
System.arraycopy(regionUVs, 0, copy.regionUVs, 0, regionUVs.length);
arraycopy(regionUVs, 0, copy.regionUVs, 0, regionUVs.length);
copy.uvs = new float[uvs.length];
System.arraycopy(uvs, 0, copy.uvs, 0, uvs.length);
arraycopy(uvs, 0, copy.uvs, 0, uvs.length);
copy.triangles = new short[triangles.length];
System.arraycopy(triangles, 0, copy.triangles, 0, triangles.length);
arraycopy(triangles, 0, copy.triangles, 0, triangles.length);
copy.hullLength = hullLength;
// Nonessential.
if (edges != null) {
copy.edges = new short[edges.length];
System.arraycopy(edges, 0, copy.edges, 0, edges.length);
arraycopy(edges, 0, copy.edges, 0, edges.length);
}
copy.width = width;
copy.height = height;

View File

@ -29,7 +29,10 @@
package com.esotericsoftware.spine.attachments;
import static com.esotericsoftware.spine.utils.SpineUtils.*;
import com.badlogic.gdx.graphics.Color;
import com.esotericsoftware.spine.PathConstraint;
/** An attachment whose vertices make up a composite Bezier curve.
@ -84,7 +87,7 @@ public class PathAttachment extends VertexAttachment {
PathAttachment copy = new PathAttachment(name);
copyTo(copy);
copy.lengths = new float[lengths.length];
System.arraycopy(lengths, 0, copy.lengths, 0, lengths.length);
arraycopy(lengths, 0, copy.lengths, 0, lengths.length);
copy.closed = closed;
copy.constantSpeed = constantSpeed;
copy.color.set(color);

View File

@ -29,10 +29,13 @@
package com.esotericsoftware.spine.attachments;
import static com.esotericsoftware.spine.utils.SpineUtils.*;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.esotericsoftware.spine.Bone;
/** An attachment that displays a textured quadrilateral.
@ -275,8 +278,8 @@ public class RegionAttachment extends Attachment {
copy.rotation = rotation;
copy.width = width;
copy.height = height;
System.arraycopy(uvs, 0, copy.uvs, 0, 8);
System.arraycopy(offset, 0, copy.offset, 0, 8);
arraycopy(uvs, 0, copy.uvs, 0, 8);
arraycopy(offset, 0, copy.offset, 0, 8);
copy.color.set(color);
return copy;
}

View File

@ -29,7 +29,10 @@
package com.esotericsoftware.spine.attachments;
import static com.esotericsoftware.spine.utils.SpineUtils.*;
import com.badlogic.gdx.utils.FloatArray;
import com.esotericsoftware.spine.Bone;
import com.esotericsoftware.spine.Skeleton;
import com.esotericsoftware.spine.Slot;
@ -170,13 +173,13 @@ abstract public class VertexAttachment extends Attachment {
void copyTo (VertexAttachment attachment) {
if (bones != null) {
attachment.bones = new int[bones.length];
System.arraycopy(bones, 0, attachment.bones, 0, bones.length);
arraycopy(bones, 0, attachment.bones, 0, bones.length);
} else
attachment.bones = null;
if (vertices != null) {
attachment.vertices = new float[vertices.length];
System.arraycopy(vertices, 0, attachment.vertices, 0, vertices.length);
arraycopy(vertices, 0, attachment.vertices, 0, vertices.length);
} else
attachment.vertices = null;

View File

@ -56,4 +56,17 @@ public class SpineUtils {
public static float atan2 (float y, float x) {
return (float)Math.atan2(y, x);
}
static public void arraycopy (Object src, int srcPos, Object dest, int destPos, int length) {
if (src == null) throw new IllegalArgumentException("src cannot be null.");
if (dest == null) throw new IllegalArgumentException("dest cannot be null.");
try {
System.arraycopy(src, srcPos, dest, destPos, length);
} catch (ArrayIndexOutOfBoundsException ex) {
throw new ArrayIndexOutOfBoundsException( //
"Src: " + java.lang.reflect.Array.getLength(src) + ", " + srcPos //
+ ", dest: " + java.lang.reflect.Array.getLength(dest) + ", " + destPos //
+ ", count: " + length);
}
}
}

View File

@ -29,6 +29,8 @@
package com.esotericsoftware.spine.utils;
import static com.esotericsoftware.spine.utils.SpineUtils.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
@ -754,7 +756,7 @@ public class TwoColorPolygonBatch implements PolygonBatch {
triangles[triangleIndex++] = (short)(polygonTriangles[i] + startVertex);
this.triangleIndex = triangleIndex;
System.arraycopy(polygonVertices, verticesOffset, vertices, vertexIndex, verticesCount);
arraycopy(polygonVertices, verticesOffset, vertices, vertexIndex, verticesCount);
this.vertexIndex += verticesCount;
}
@ -821,7 +823,7 @@ public class TwoColorPolygonBatch implements PolygonBatch {
}
this.triangleIndex = triangleIndex;
System.arraycopy(spriteVertices, offset, vertices, vertexIndex, count);
arraycopy(spriteVertices, offset, vertices, vertexIndex, count);
this.vertexIndex += count;
}