I have only added several lines to the tutorial example "Game Level", here is the Main.cpp code:
// Dark GDK - The Game Creators - www.thegamecreators.com
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
// switch to the media directory, load our world
// and turn lighting off
SetCurrentDirectory ( "media" );
dbLoadObject ( "universe.dbo", 1 );
dbSetObjectCollisionToPolygons(1);//added by Carlos
dbSetObjectLight ( 1, 0 );
// load a model for our sky
dbLoadObject ( "skybox2.x", 2 );
dbSetObjectLight ( 2, 0 );
dbSetObjectTexture ( 2, 3, 2 );
dbScaleObject ( 2, 5000, 5000, 5000 );
dbSetObjectCollisionToPolygons(2);//added by Carlos
// position the camera
dbPositionCamera ( 434, 42, -517 );
dbAutomaticCameraCollision (0, 10, 1);//added by Carlos
// camera variables
float fCameraAngleX = 0.0f;
float fCameraAngleY = 0.0f;
float distance=0;//added by Carlos
// our main loop
while ( LoopGDK ( ) )
{
// move the camera using the arrow keys
dbControlCameraUsingArrowKeys ( 0, 5.0f, 0.3f );
if(dbUpKey())//added by Carlos
{
distance=dbIntersectObject(1,dbCameraPositionX()+15*dbSin(dbCameraAngleY()),dbCameraPositionY(),dbCameraPositionZ()+15*dbCos(dbCameraAngleY()),dbCameraPositionX()+15*dbSin(dbCameraAngleY()),-1000,dbCameraPositionZ()+15*dbCos(dbCameraAngleY()));
distance = dbCameraPositionY() + 42 - distance;
dbPositionCamera(dbCameraPositionX(),distance,dbCameraPositionZ());
}
else if(dbDownKey())//added by Carlos
{
distance=dbIntersectObject(1,dbCameraPositionX()+15*dbSin(dbCameraAngleY()),dbCameraPositionY(),dbCameraPositionZ()-15*dbCos(dbCameraAngleY()),dbCameraPositionX()+15*dbSin(dbCameraAngleY()),-1000,dbCameraPositionZ()-15*dbCos(dbCameraAngleY()));
distance = dbCameraPositionY() + 42 - distance;
dbPositionCamera(dbCameraPositionX(),distance,dbCameraPositionZ());
}
// create a rotation axis based on mouse movement
//fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.4f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.4f );
// rotate camera
//dbXRotateCamera ( fCameraAngleX );
dbYRotateCamera ( fCameraAngleY );
// update the screen
dbSync ( );
}
dbDeleteObject(1);
dbDeleteObject(2);
dbFlushVideoMemory();
// return back to windows
return ;
}
I think it is the .dbo file that makes this memory leak problem.
Because I have tried to comment out load the dbo file and the .x skybox works very well.
But when I added back the dbo file, the problem was back.
The .dbo file was made by WorldStudio and it is consisted of many components. It's quite complex. The textures are put in several sub directories so that it can't be freed cleanly?