简体   繁体   English

NVIDIA未处理的异常,位于0x002a2da2中 <work.exe> 0xC0000005:访问冲突读取位置0x00000000

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

I am currently trying to make two arms on a character and use NxRevoluteJoint for their movement. 我目前正在尝试在角色上伸出两只手臂,并使用NxRevoluteJoint进行移动。 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. 我知道指针在某些地方是对NULL的引用,但我看不出如何对其进行整理。

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); 我得到错误的行是在playerLeftJoint->setLimits(limit1);

CreateRevoluteJoint is returning a null pointer, simple as that. CreateRevoluteJoint返回一个空指针,就这么简单。 The error message makes it very clear that the pointer has a value of 0 . 该错误消息非常清楚地表明指针的值为0 Of course, you didn't post that function, so that's the best information I can give you. 当然,您没有发布该功能,所以这是我能为您提供的最佳信息。 As such, this line; 因此,这条线;

playerLeftJoint->setLimits(limit1);

dereferences the pointer playerLeftJoint , which is an invalid pointer. 解引用指针playerLeftJoint ,它是无效的指针。 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; 我看不到您的整个程序结构,因此在这种情况下,最简单的解决方法是:

if(!playerLeftJoint)
    playerLeftJoint = new NxRevoluteJoint();

// same for the other pointer, now they are valid

Additionally, as this is C++ and not C, use a smart pointer to handle memory for you, ie, 另外,由于这是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(...));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 tester.exe中0x00b21840处未处理的异常:0xC0000005:访问冲突读取位置0x00000000 - Unhandled exception at 0x00b21840 in tester.exe: 0xC0000005: Access violation reading location 0x00000000 0xC0000005:访问冲突读取位置0x00000000 - 0xC0000005: Access violation reading location 0x00000000 0xC0000005:访问冲突读取位置0x00000000 - 0xC0000005: Access violation reading location 0x00000000 在0xC0000005中的0x6ececafa出现未处理的异常:访问冲突写入位置0x00000000 - Unhandled Exception as at 0x6ececafa in 0xC0000005 : Access violation writing location 0x00000000 在 Project0_opengl.exe 中的 0x00000000 处抛出异常:0xC0000005:访问冲突执行位置 0x00000000 - Exception thrown at 0x00000000 in Project0_opengl.exe: 0xC0000005: Access violation executing location 0x00000000 在 CobwebDiagram.exe 中的 0x00000000 处引发异常:0xC0000005:访问冲突执行位置 0x00000000 - Exception thrown at 0x00000000 in CobwebDiagram.exe: 0xC0000005: Access violation executing location 0x00000000 Engine.exe中0x00000000的未处理异常:0xC0000005:访问冲突 - Unhandled exception at 0x00000000 in Engine.exe: 0xC0000005: Access violation 模拟Clock.exe中0x00BF57F9处未处理的异常:0xC0000005:访问冲突读取位置0x00000000 - Unhandled exception at 0x00BF57F9 in Analog Clock.exe: 0xC0000005: Access violation reading location 0x00000000 Metrics_Alpha.exe 中 0x78F90870 (ucrtbased.dll) 处的未处理异常:0xC0000005:访问冲突读取位置 0x00000000 - Unhandled exception at 0x78F90870 (ucrtbased.dll) in Metrics_Alpha.exe: 0xC0000005: Access violation reading location 0x00000000 application.exe中0x0872340b(CAN.dll)的未处理异常:0xC0000005:访问冲突读取位置0x00000000 - Unhandled exception at 0x0872340b (CAN.dll) in application.exe: 0xC0000005: Access violation reading location 0x00000000
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM