Hi all, I've been working on implementing Tokamak Physics engine into my game engine. Now, it all started out nicely. I downloaded the libraries, got my engine to compile with it etc. So here I am, I wrote a physicshandler class. However, trouble already arrises at the initialize function,
physicshandler.cpp
#ifdef WIN32
#include <windows.h>
#endif
// Engine headers
#include "common.h"
#include "system.h"
using namespace Led::System;
using namespace Led::Math;
/// Constructor.
PhysicsHandler::PhysicsHandler()
{
sim = NULL;
}
/// Initialize. Initializes the physics manager and preserves space for the amount of bodies.
/// @variable int rigbodies the amount of rigid bodies.
/// @variable int animbodies the amount of animated bodies.
int PhysicsHandler::Initialize(int rigbodies, int animbodies)
{
unsigned long totalbodies = 0;
neSimulatorSizeInfo sizeinfo;
// Setup our physics engine info.
sizeinfo.rigidBodiesCount = rigbodies;
sizeinfo.animatedBodiesCount = animbodies;
// Calculate the total amount of bodies.
totalbodies = sizeinfo.rigidBodiesCount + sizeinfo.animatedBodiesCount;
sizeinfo.geometriesCount = totalbodies;
// Calculate the max pair of overlapping bodies.
sizeinfo.overlappedPairsCount = totalbodies * (totalbodies - 1) / 2;
sizeinfo.rigidParticleCount = 0;
sizeinfo.constraintsCount = 0;
sizeinfo.terrainNodesStartCount = 0;
// Set our gravity.
gravity.Set(0.0f, -10.0f, 0.0f);
// Finally create our simulator.
sim = neSimulator::CreateSimulator(sizeinfo, NULL, &gravity);
return 0;
}
/// Run. Runs the physics every frame.
int PhysicsHandler::Run()
{
if (sim != NULL)
sim->Advance(1, 2, NULL);
return 0;
}
/// Destroy. Destroys the physics manager.
int PhysicsHandler::Destroy()
{
// Destroy the simulator.
neSimulator::DestroySimulator(sim);
// Set sim to NULL.
sim = NULL;
return 0;
}
/// SetTerrainMesh. Sets the terrainmesh pointer.
/// @variable neTriangleMesh mesh the new mesh.
int PhysicsHandler::SetTerrainMesh(neTriangleMesh *mesh)
{
if (sim)
if (mesh != NULL)
sim->SetTerrainMesh(mesh);
return 0;
}
/// GetSimulator. Returns a pointer to the simulator.
neSimulator *PhysicsHandler::GetSimulator()
{
return sim;
}
physicshandler.h
#ifndef PHYSICSHANDLER_H
#define PHYSICSHANDLER_H
namespace Led
{
namespace System
{
class PhysicsHandler
{
public:
/// Constructor.
PhysicsHandler();
/// Initialize. Initializes the physics handler and preserves space for the amount of bodies.
/// @variable int rigbodies the amount of rigid bodies.
/// @variable int animbodies the amount of animated bodies.
int Initialize(int rigbodies, int animbodies);
/// Run. Updates the physics every frame at the given speed.
int Run();
/// Destroy. Destroys the physics handler.
int Destroy();
/// SetTerrainMesh. Sets the terrainmesh pointer.
/// @variable neTriangleMesh mesh the new mesh.
int SetTerrainMesh(neTriangleMesh *mesh);
/// GetSimulator. Returns a pointer to the simulator.
neSimulator *GetSimulator();
private:
neV3 gravity;
neSimulator *sim;
};
};
};
#endif
For some reason, I get this error:
Unhandled exception at 0x003d273f in LedEngine.exe: 0xC0000005: Access violation writing location 0x00000000.
With VC++'s debugger pointing at the return 0; line of the Initialize function.
Does anybody know if I am doing something incorrectly and if the problem lies within that function ?
[EDIT!!!!!!!]
This problem has already been fixed, read below for my other problem.
[/EDIT!!!!!!!]
[Edited by - PinguinDude on July 23, 2007 4:40:32 PM]
http://sourceforge.net/projects/pingux/ <-- you know you wanna see my 2D Engine which supports DirectX and OpenGL or insert your renderer here :)