Well, i'm trying to set up PhysX but something just doesn't want to work, the createSDK function fails with this:
+ &errorCode 0xcccccca8 <Bad Ptr> char *
here's my class header for PhysX:
#ifndef PHYS_X_H
#define PHYS_X_H
#define NOMINMAX
#include <Windows.h>
#include <Nx.h>
#include <NxPhysics.h>
#include <PhysXLoader.h>
#include "UserAllocator.h"
#pragma comment(lib,"PhysXLoader.lib")
class ErrorStream : public NxUserOutputStream
{
public:
void reportError(NxErrorCode e, const char* message, const char* file, int line)
{
char Buffer[400];
sprintf_s(Buffer,"The Message is: %s %s (%d) :",message, file, line);
MessageBoxA(NULL,Buffer,"",MB_OK);
switch (e)
{
case NXE_INVALID_PARAMETER:
sprintf_s(Buffer,"Invalid Parameter");
MessageBoxA(NULL,Buffer,Buffer,MB_OK);
break;
case NXE_INVALID_OPERATION:
sprintf_s(Buffer, "invalid operation");
MessageBoxA(NULL,Buffer,Buffer,MB_OK);
break;
case NXE_OUT_OF_MEMORY:
sprintf_s(Buffer, "out of memory");
MessageBoxA(NULL,Buffer,Buffer,MB_OK);
break;
case NXE_DB_INFO:
sprintf_s(Buffer, "info");
MessageBoxA(NULL,Buffer,Buffer,MB_OK);
break;
case NXE_DB_WARNING:
sprintf_s(Buffer, "warning");
MessageBoxA(NULL,Buffer,Buffer,MB_OK);
break;
default:
sprintf_s(Buffer,"unknown error");
MessageBoxA(NULL,Buffer,Buffer,MB_OK);
}
sprintf_s(Buffer," : %s\n", message);
MessageBoxA(NULL,Buffer,Buffer,MB_OK);
}
NxAssertResponse reportAssertViolation(const char* message, const char* file, int line)
{
printf("access violation : %s (%s line %d)\n", message, file, line);
#ifdef WIN32
switch (MessageBoxA(0, message, "AssertViolation, see console for details.", MB_ABORTRETRYIGNORE))
{
case IDRETRY:
return NX_AR_CONTINUE;
case IDIGNORE:
return NX_AR_IGNORE;
case IDABORT:
default:
return NX_AR_BREAKPOINT;
}
#elif LINUX
assert(0);
#elif _XBOX
return NX_AR_BREAKPOINT;
#elif __CELLOS_LV2__
return NX_AR_BREAKPOINT;
#elif __PPCGEKKO__
return NX_AR_BREAKPOINT;
#endif
}
void print(const char* message)
{
printf(message);
}
};
class PhysXMgr
{
public:
PhysXMgr();
~PhysXMgr();
bool init_physXEngine();
void update();
private:
NxPhysicsSDK* pPhysXSDK;
NxScene* pScene;
UAloc* pUAloc;
NxPhysicsSDKDesc PhysXDesc;
NxSceneDesc SceneDesc;
};
#endif
and here is the cpp file:
#include "PhysX.h"
const char* getNxSDKCreateError(const NxSDKCreateError& errorCode)
{
switch(errorCode)
{
case NXCE_NO_ERROR: return "NXCE_NO_ERROR";
case NXCE_PHYSX_NOT_FOUND: return "NXCE_PHYSX_NOT_FOUND";
case NXCE_WRONG_VERSION: return "NXCE_WRONG_VERSION";
case NXCE_DESCRIPTOR_INVALID: return "NXCE_DESCRIPTOR_INVALID";
case NXCE_CONNECTION_ERROR: return "NXCE_CONNECTION_ERROR";
case NXCE_RESET_ERROR: return "NXCE_RESET_ERROR";
case NXCE_IN_USE_ERROR: return "NXCE_IN_USE_ERROR";
default: return "Unknown error";
}
};
PhysXMgr::PhysXMgr()
{
}
PhysXMgr::~PhysXMgr()
{
pPhysXSDK->release();
}
bool PhysXMgr::init_physXEngine()
{
if(!pUAloc)
{
pUAloc = new UAloc;
}
NxSDKCreateError errorCode = NXCE_NO_ERROR;
pPhysXSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION,pUAloc,new ErrorStream(),PhysXDesc,&errorCode );
if(pPhysXSDK)
{
pPhysXSDK->setParameter(NX_SKIN_WIDTH,0.05f);
if(pPhysXSDK->getHWVersion() == NX_HW_VERSION_ATHENA_1_0)
{
SceneDesc.simType = NX_SIMULATION_HW;
}
else
{
SceneDesc.simType = NX_SIMULATION_SW;
}
SceneDesc.gravity = NxVec3(0,-9.86,0);
pScene = pPhysXSDK->createScene(SceneDesc);
if(pScene == NULL)
{
MessageBoxA(NULL,"Scene Not Created","",MB_OK);
exit(-1);
return false;
}
NxMaterial* defMat = pScene->getMaterialFromIndex(0);
defMat->setRestitution(0.0f);
defMat->setStaticFriction(0.5f);
defMat->setDynamicFriction(0.5f);
}
else if(pPhysXSDK == NULL)
{
char Buffer[400];
sprintf_s(Buffer,"PhysX Error code: %s",getNxSDKCreateError(errorCode));
MessageBoxA(NULL,Buffer,Buffer,MB_OK);
return false;
}
}
void PhysXMgr::update()
{
if(pScene)
{
pScene->setTiming();
}
}
not sure if you need the muteX class and the UserAlloc classes
"Originally I was going to have a BS on it but you know how that would be. I can't walk around with the letters BS on me." More or less a qoute by Syndrome from Jack, Jack, attack