1

私は現在、キャラクターに2つの腕を作り、その動きにNxRevoluteJointを使用しようとしています。例として挙げた別のプログラムでこれらを完全に機能させ、この新しいプロジェクトで同じコードを使用しましたが、エラー(タイトルの1つ)が発生し、修正方法に苦労しています。ポインタがどこかでNULLを参照していることは理解していますが、それを分類する方法がわかりません。

変数はグローバルに設定されます。

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

4

1 に答える 1

1

CreateRevoluteJointは、そのように単純なnullポインタを返します。エラーメッセージは、ポインタの値が。であることを非常に明確に示しています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(...));
于 2013-01-01T18:52:22.080 に答える