Skip to content

Commit b60d358

Browse files
authored
Fix the issue where the cache space for indices is smaller than actually required due to indices not being updated. (#18936)
* Fix the issue where the cache space for indices is smaller than actually required due to indices not being updated. * synchronize logic to realTime mode * refine
1 parent 2c05e20 commit b60d358

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cocos/spine/assembler/simple.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,20 @@ function realTimeTraverse (comp: Skeleton): void {
161161
if (rd.vertexCount < vc || rd.indexCount < ic) {
162162
rd.resize(Math.ceil(vc * ADJUST_SIZE_RATE), Math.ceil(ic * ADJUST_SIZE_RATE));
163163
}
164-
rd.indices = new Uint16Array(ic);
165164
comp._vLength = vc * Float32Array.BYTES_PER_ELEMENT * floatStride;
166165
comp._vBuffer = new Uint8Array(rd.chunk.vb.buffer, rd.chunk.vb.byteOffset, comp._vLength);
167166
comp._iLength = Uint16Array.BYTES_PER_ELEMENT * ic;
167+
}
168+
if (!rd.indices || rd.indices.length < ic) {
169+
//rd.indexCount maybe equal to ic, but rd.indices.length may be less than ic, so we need to reallocate indices
170+
rd.indices = new Uint16Array(ic);
168171
comp._iBuffer = new Uint8Array(rd.indices.buffer);
169172
}
170173

171174
const vbuf = rd.chunk.vb;
172175
const vPtr: number = model.vPtr;
173176
const iPtr: number = model.iPtr;
174-
const ibuf = rd.indices!;
177+
const ibuf = rd.indices;
175178
const HEAPU8: Uint8Array = spine.wasmUtil.wasm.HEAPU8;
176179

177180
comp._vBuffer?.set(HEAPU8.subarray(vPtr, vPtr + comp._vLength), 0);
@@ -284,6 +287,9 @@ function cacheTraverse (comp: Skeleton): void {
284287
if (rd.vertexCount < vc || rd.indexCount < ic) {
285288
rd.resize(Math.ceil(vc * ADJUST_SIZE_RATE), Math.ceil(ic * ADJUST_SIZE_RATE));
286289
}
290+
}
291+
if (!rd.indices || rd.indices.length < ic) {
292+
//rd.indexCount maybe equal to ic, but rd.indices.length may be less than ic, so we need to reallocate indices
287293
rd.indices = new Uint16Array(ic);
288294
}
289295

@@ -318,7 +324,7 @@ function cacheTraverse (comp: Skeleton): void {
318324
}
319325
}
320326

321-
const iUint16Buf = rd.indices!;
327+
const iUint16Buf = rd.indices;
322328
iUint16Buf.set(model.iData as TypedArray);
323329
const chunkOffset = rd.chunk.vertexOffset;
324330
for (let i = 0; i < ic; i++) {

0 commit comments

Comments
 (0)