-2
Havok을 Irrlicht 엔진에 통합하려고합니다. 이제 간단한 구형을 만들려고합니다. 그러나 새로운 Entity를 푸시하려고 할 때 예외가 발생합니다. 문제가 무엇입니까?
여기 는 클래스 선언,std :: list push back은 처리되지 않은 예외를 발생시킵니다. 액세스 위반
class IrrHBody
{
public:
IrrHBody() { Node = nullptr, Phys = nullptr;};
scene::ISceneNode *Node;
hkpRigidBody* Phys ;
};
void CreateSphere(const hkVector4 &TPosition, hkReal TRadius, hkReal TMass) {
IrrHBody* body = new IrrHBody;
Objects.push_back(body); //<---------THATS OKAY
// Create an Irrlicht sphere
body->Node = irrScene->addSphereSceneNode(TRadius, 32);
body->Node->setMaterialFlag(video::EMF_LIGHTING, 1);
body->Node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
// Create a moving sphere
hkReal sphereRadius = 0.5f;
hkpConvexShape* sphereShape = new hkpSphereShape(sphereRadius);
hkpRigidBodyCinfo sphereInfo;
sphereInfo.m_shape = sphereShape;
sphereInfo.m_position.set(0.0f, 50.0f, 0.0f);
sphereInfo.m_motionType = hkpMotion::MOTION_SPHERE_INERTIA;
// Compute mass properties
hkReal sphereMass = 10.0f;
hkMassProperties sphereMassProperties;
hkpInertiaTensorComputer::computeSphereVolumeMassProperties(sphereRadius, sphereMass, sphereMassProperties);
sphereInfo.m_inertiaTensor = sphereMassProperties.m_inertiaTensor;
sphereInfo.m_centerOfMass = sphereMassProperties.m_centerOfMass;
sphereInfo.m_mass = sphereMassProperties.m_mass;
// Create sphere RigidBody
body->Phys = new hkpRigidBody(sphereInfo);
sphereShape->removeReference();
World->addEntity(body->Phys);
Objects.push_back(body); <------- Exception
}
P.S.입니다 처음 Havok을 만났습니다.
코드를 줄이고 누락 된 부분을 추가하십시오. 예를 들어'Objects'가 선언 된 부분은? 즉,'new'를 사용했다면 Java 배경에서 나온 것이지만 C++에서는 그렇게하는 것이 나쁜 생각입니다. 즉, 어떤 예외가 정확하게 잡히지 않았습니까? –
malloc을 사용해야합니까? 아니, 나는 항상 C++ (학생)이었다. 누락 된 부품 만 정적 목록 개체; –
Warezovvv
아니요, 정말로 필요한 경우가 아니라면 동적 할당이없는 일반 개체를 사용하십시오. 'int * i = new int (0)'도 쓰지 않지만'int i = 0'라고 쓴다. 예를 들어'list'을 사용해보십시오. –