holodeck icon indicating copy to clipboard operation
holodeck copied to clipboard

Incorrect size calculation in RelativeSkeletalPositionSensor

Open insooneelife opened this issue 4 years ago • 2 comments

Hello guys I found a weird code in RelativeSkeletalPositionSensor.cpp

//code
void URelativeSkeletalPositionSensor::TickSensorComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
	float* FloatBuffer = static_cast<float*>(Buffer);
	for (int i = 0; i < Bones.Num(); i++) {

		FQuat BoneQ = SkeletalMeshComponent->GetBoneQuaternion(Bones[i], EBoneSpaces::WorldSpace);
		FQuat ParentQ = SkeletalMeshComponent->GetBoneQuaternion(ParentBones[i], EBoneSpaces::WorldSpace);
		FQuat Quat = ParentQ.Inverse() * BoneQ;
		FloatBuffer[4 * i] = Quat.X;
		FloatBuffer[4 * i + 1] = Quat.Y;
		FloatBuffer[4 * i + 2] = Quat.Z;
		FloatBuffer[4 * i + 3] = Quat.W;
	}
}

int URelativeSkeletalPositionSensor::GetNumItems() {
	return this->Bones.Num();
}

at the code, TickSensorComponent() ~ FloatBuffer[4 * i] = Quat.X; FloatBuffer[4 * i + 1] = Quat.Y; FloatBuffer[4 * i + 2] = Quat.Z; FloatBuffer[4 * i + 3] = Quat.W; ~ they are accessing array index up to BoneNum*4,

but in the code, GetNumItems() it just returns Bone.Num().

Shouldn't this code be changed like this?

int URelativeSkeletalPositionSensor::GetNumItems() {
	return this->Bones.Num() * 4;
}

insooneelife avatar Mar 20 '20 06:03 insooneelife

Yes, that probably should be changed, but it currently isn't causing any issues. That GetNumItems is used to allocate the size of the shared memory buffer if the client hasn't already done so. Since the client normally runs first, and it's calculation is correct, we haven't seen anything.

Thank you for pointing this out.

We should spot check the rest of the sensors to make sure that they are the same on both sides.

jaydenmilne avatar Mar 31 '20 14:03 jaydenmilne

@jaydenmilne, from your comment above, is this a bug?

daniekpo avatar May 06 '20 02:05 daniekpo