From 7d7e0965dc2db09af1191dba87101714291d9f46 Mon Sep 17 00:00:00 2001 From: Gonzalo DCL Date: Mon, 16 Sep 2024 15:18:38 -0300 Subject: [PATCH] fix tween sync entity --- .../@dcl/ecs/src/serialization/crdt/network/utils.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/@dcl/ecs/src/serialization/crdt/network/utils.ts b/packages/@dcl/ecs/src/serialization/crdt/network/utils.ts index dfdafdefb..77c0753da 100644 --- a/packages/@dcl/ecs/src/serialization/crdt/network/utils.ts +++ b/packages/@dcl/ecs/src/serialization/crdt/network/utils.ts @@ -63,23 +63,25 @@ export function localMessageToNetwork( destinationBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false) } +const buffer = new ReadWriteByteBuffer() /* istanbul ignore next */ export function fixTransformParent( message: ReceiveMessage, transformValue?: TransformType, parent?: Entity ): Uint8Array { + buffer.resetBuffer() let transform = transformValue - const buffer = new ReadWriteByteBuffer() + if (!transform && 'data' in message) { - buffer.writeBuffer(message.data) - transform = TransformSchema.deserialize(buffer) - buffer.resetBuffer() + transform = TransformSchema.deserialize(new ReadWriteByteBuffer(message.data)) } + if (!transform) throw new Error('Invalid parent transform') + // Generate new transform raw data with the parent const newTransform = { ...transform, parent } - buffer.resetBuffer() + TransformSchema.serialize(newTransform, buffer) return buffer.toBinary() }