I am currently trying to make two arms on a character and use NxRevoluteJoint for their movement. I have these working perfectly in another program that has been given as an example and I have used the same code in this new project however I am getting an error (the one in the title) and I am struggling how to fix it. I understand that the pointers is reference to NULL at some place but I can’t see how to sort it out.
The variables are set globally:
NxRevoluteJoint* playerLeftJoint= 0;
NxRevoluteJoint* playerRightJoint= 0;
This is the code in the seperate function where the player is being built as a compound object:
NxVec3 globalAnchor(0,1,0);
NxVec3 globalAxis(0,0,1);
playerLeftJoint= CreateRevoluteJoint(0,actor2,globalAnchor,globalAxis);
playerRightJoint= CreateRevoluteJoint(0,actor2,globalAnchor,globalAxis);
//set joint limits
NxJointLimitPairDesc limit1;
limit1.low.value = -0.3f;
limit1.high.value = 0.0f;
playerLeftJoint->setLimits(limit1);
NxJointLimitPairDesc limit2;
limit2.low.value = 0.0f;
limit2.high.value = 0.3f;
playerRightJoint->setLimits(limit2);
NxMotorDesc motorDesc1;
motorDesc1.velTarget = 0.15;
motorDesc1.maxForce = 1000;
motorDesc1.freeSpin = true;
playerLeftJoint->setMotor(motorDesc1);
NxMotorDesc motorDesc2;
motorDesc2.velTarget = -0.15;
motorDesc2.maxForce = 1000;
motorDesc2.freeSpin = true;
playerRightJoint->setMotor(motorDesc2);
The line where I am getting the error is at the playerLeftJoint->setLimits(limit1);
CreateRevoluteJointis returning a null pointer, simple as that. The error message makes it very clear that the pointer has a value of0. Of course, you didn’t post that function, so that’s the best information I can give you. As such, this line;dereferences the pointer
playerLeftJoint, which is an invalid pointer. You need to initialize your pointers. I can’t see your entire program structure, so in this case the most simple fix would be something like;Additionally, as this is C++ and not C, use a smart pointer to handle memory for you, i.e.,