NVIDIA 在 <work.exe>0xC0000005 中0x002a2da2未处理的异常:访问违规读取位置0x00000000

NVIDIA Unhandled exception at 0x002a2da2 in <work.exe>0xC0000005: Access violation reading location 0x00000000

本文关键字:访问 异常 读取 0x00000000 位置 0x002a2da2 work lt exe gt NVIDIA      更新时间:2023-10-16

我目前正在尝试在角色上制作两个臂,并使用nxrevoluteXoint进行运动。我在另一个程序中提供了完美的工作,该程序以示例为例,并且在这个新项目中使用了相同的代码,但是我遇到了一个错误(标题中的一个),并且我正在努力解决它。我知道指针是在某个地方提到的,但我看不到如何解决。

变量是全球设置的:

NxRevoluteJoint* playerLeftJoint= 0;
NxRevoluteJoint* playerRightJoint= 0;

这是单独函数中的代码,其中播放器作为复合对象构建:

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);

我在playerLeftJoint->setLimits(limit1);

上获得错误的线路

CreateRevoluteJoint正在返回一个空指针,这样简单。错误消息非常清楚,指针的值为0。当然,您没有发布该功能,所以这是我可以提供的最好的信息。因此,这线;

playerLeftJoint->setLimits(limit1);

表示指针playerLeftJoint,这是无效的指针。您需要初始化指针。我看不到您的整个程序结构,因此在这种情况下,最简单的修复将是;

if(!playerLeftJoint)
    playerLeftJoint = new NxRevoluteJoint();
// same for the other pointer, now they are valid

此外,由于这是C ,而不是C,请使用智能指针为您处理内存,即

#include <memory>
std::unique_ptr<NxRevoluteJoint> playerLeftJoint;
// or, if you have a custom deallocater...
std::unique_ptr<NxRevoluteJoint, RevoluteJointDeleter> playerLeftJoint;
// ...
playerLeftJoint.reset(new NxRevoluteJoint(...));