NVIDIA 在 <work.exe>0xC0000005 中0x002a2da2未处理的异常:访问违规读取位置0x00000000
NVIDIA Unhandled exception at 0x002a2da2 in <work.exe>0xC0000005: Access violation reading location 0x00000000
我目前正在尝试在角色上制作两个臂,并使用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(...));
相关文章:
- 引发异常:读取访问冲突**dynamicArray**为0x1118235.发生
- 写入访问冲突异常
- 在类 12.exe 中0x7B37FF80 (ucrtbased.dll) 引发异常: 0xC0000005:访问冲突读
- 堆栈上的 C++ 访问冲突写入异常
- 引发异常:写访问冲突. temp 为 nullptr
- 在C++中删除双向链表的头节点后出现访问冲突异常
- 从二进制文件中读取元素时引发异常(引发异常:读取访问冲突. _Pnext 0xB414D4)
- 引发异常:读取访问冲突.**此**0x40错误
- (此函数用于计算 SMA).在 FA.exe 中0x00509159引发异常: 0xC0000005:访问冲突读取位置0
- 当我尝试访问结构类型时,我收到 std::bad_variant_access 异常
- 抛出的 Visual Studio 异常:写入访问冲突。q_deck->p_deck 0x110112。C 语言
- Visual Studio图形调试器引发读取访问冲突异常
- C++中的内存分配(引发异常:读取访问冲突)
- 为什么访问模板化变体作为返回值抛出异常
- 存在内存访问异常,但我不确定我的代码中出了什么问题
- 函数引发写入访问异常
- 使用XMVector时的内存访问异常
- 根据CIN类型插入空隙*?始终获取unsigned_char的访问异常
- 如何调试C++非托管代码中的较低级别文件访问异常/崩溃
- log4cxx访问异常,使用<<运算符和宏