Well, right to the issue!
This is called when you are finished with the class.
FORCEINLINE void
TriangleSoup::Release( )
{
// NOW: bad calling convention or stack mutililation
PhysicsAPIInternal()->RemoveFromSimulation( this );
delete this;
}
The commented line causes the following error:
"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."
I don't really know why!
This code is run inside the game dll, TriangleSoup is in a lib and PhysicsAPIInternal is calling a global gotten from the physicssystem dll.
Here is some of the relavent sources truncated to important bits:
TriangleSoup.h
class TriangleSoup: public ICollide
{
void Link( OcTree< ICollide* >::Node* node );
const Vector< OcTree< ICollide* >::Node* >* GetLinks( );
void Unlink( );
void Release( );
private:
Vector< OcTree< ICollide* >::Node* > backlinks_; // broadphase backlinks
};
#include "trianglesoup.inl"
TriangleSoup.inl
FORCEINLINE void
TriangleSoup::Link( OcTree< ICollide* >::Node* node )
{
backlinks_.InsertBack( node );
}
FORCEINLINE const Vector< OcTree< ICollide* >::Node* >*
TriangleSoup::GetLinks( )
{
return &backlinks_;
}
FORCEINLINE void
TriangleSoup::Unlink( )
{
for( uint32 i = 0; i < backlinks_.GetCount(); ++i )
{
backlinks_[ i ]->RemoveObject( this );
}
backlinks_.RemoveAll();
}
FORCEINLINE void
TriangleSoup::Release( )
{
// NOW: bad calling convention or stack mutililation
PhysicsAPIInternal()->RemoveFromSimulation( this );
delete this;
}
PhysicsSystem.h
class IPhysicsSystemInternal
{
public:
virtual ~IPhysicsSystemInternal( ) { ; }
virtual void AddToSimulation( ICollide* collide ) = 0;
virtual void RemoveFromSimulation( ICollide* collide ) = 0;
};
class PhysicsSystem: public IPhysicsSystemInternal, public IPhysicsSystem
{
public:
PhysicsSystem( );
~PhysicsSystem( );
void AddToSimulation( ICollide* collide );
void RemoveFromSimulation( ICollide* collide );
};
// Internal Accessor
FORCEINLINE IPhysicsSystemInternal* PhysicsAPIInternal( )
{
extern IPhysicsSystem* _g_PhysicsSystemInstance;
Assert( _g_PhysicsSystemInstance );
return (IPhysicsSystemInternal*)_g_PhysicsSystemInstance;
}
PhysicsSystem.cpp
void
PhysicsSystem::AddToSimulation( ICollide* collide )
{
// link to octree
Extents extents;
collide->GetExtents( extents );
ocTree_.AddObject( collide, extents );
// add to simualted entities
simulatedCollides_.InsertBack( collide );
}
void
PhysicsSystem::RemoveFromSimulation( ICollide* collide )
{
// unlink from octree
collide->Unlink();
// remove from simulated entities
simulatedCollides_.FindFirstAndRemove( collide );
}
I'm not sure where to start here!
Thanks allot guys as usual.