Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This is a long shot ... but I'm going to paste in my code to see if anyone can figure out where my memory leak is coming from.

It's a lot of code... so I advise you NOT to bother answering this unless you're really bored/really kind :D

#include "SDKsound.h"
#include "Nig.h"
#include "DXUT.h"
#include "DXUTgui.h"
#include "DXUTmisc.h"
#include "DXUTCamera.h"
#include "DXUTSettingsDlg.h"
#include "SDKmisc.h"
#include "SDKmesh.h"
#include "resource.h"
#include "Thing3D.h"
#include "Thing3DObj.h"
#include "AllThings.h"
#include "Fire.h"
//#include "D3DEnumeration.h"
#include <list>
#include <sstream>


//#define DEBUG_VS   // Uncomment this line to debug D3D9 VERTEX shaders 
//#define DEBUG_PS   // Uncomment this line to debug D3D9 pixel shaders 


    HWND              m_hWnd;              // The main app window
CFirstPersonCamera          g_Camera;               // A model viewing camera
CDXUTDialogResourceManager  g_DialogResourceManager; // manager for shared resources of dialogs
CD3DSettingsDlg             g_SettingsDlg;          // Device settings dialog
CDXUTTextHelper*            g_pTxtHelper = NULL;
CDXUTDialog                 g_HUD;                  // dialog for standard controls
CDXUTDialog                 g_SampleUI;             // dialog for sample specific controls

// Direct3D 9 resources
extern ID3DXFont*           g_pFont9;
extern ID3DXSprite*         g_pSprite9;


// Direct3D 10 resources
ID3DX10Font*                g_pFont10 = NULL;
ID3DX10Sprite*              g_pSprite10 = NULL;
ID3D10Effect*               g_pEffect10 = NULL;
ID3D10InputLayout*          g_pVERTEXLayout = NULL;
ID3D10EffectMatrixVariable* g_pmWorldViewProj = NULL;
ID3D10EffectMatrixVariable* g_pmWorld = NULL;
ID3D10EffectScalarVariable* g_pfTime = NULL;
LPD3DXFONT                  m_font;


EffectForAbstractThing3D *g_p_Effect;
Thing3DObj              *box;
Thing3D                 *gameFloor;

Thing3D                 *character;
Thing3D                 *leftWing;
Thing3D                 *rightWing;

AllThings               *all;
Fire                    *shoot;
//Camera                    *cam;
bool        fire                    = false;

//Amount of boxes destroyed in the game
int         boxCount        = -1;
int         frameCount      = 0;
int         difficulty      = 16;
//Thing3D                  *floor;
float       camRotateY     = 0.0;
float       boxTimer     = 0.0;


bool        g_b_WButtonDown         = false;    //Status of keyboard.  Thess are set
bool        g_b_SButtonDown         = false;    //in the callback KeyboardProc(), and 
bool        g_b_AButtonDown         = false;    //are used in onFrameMove().
bool        g_b_DButtonDown         = false;
bool        g_b_QButtonDown         = false;
bool        g_b_EButtonDown         = false;
bool        g_b_ShiftButtonDown     = false;
bool        g_b_SpaceButtonDown     = false;
bool        g_b_ReturnButtonDown    = false;


bool        startScreen             = true;

//Define the Keyboard keys for game play
#define VK_W              0x57
#define VK_S              0x53
#define VK_A              0x41
#define VK_D              0x44
#define VK_Q              0x51
#define VK_E              0x45

bool        g_b_CameraOnThing      = false;




// Wing Movements
bool flapDown = false;
bool leftFlapDown = false;

float leftFlap;
float rightFlap;
float flap;
//--------------------------------------------------------------------------------------
// UI control IDs
//--------------------------------------------------------------------------------------
#define IDC_TOGGLEFULLSCREEN    1
#define IDC_TOGGLEREF           2
#define IDC_CHANGEDEVICE        3
#define IDC_TOGGLEWARP          4


//--------------------------------------------------------------------------------------
// Forward declarations 
//--------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing,
                          void* pUserContext );
void CALLBACK OnKeyboard( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext );
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext );
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext );
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext );

extern bool CALLBACK IsD3D9DeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat,
                                             bool bWindowed, void* pUserContext );
extern HRESULT CALLBACK OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice,
                                            const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext);
extern HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
                                           void* pUserContext );
extern void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime,
                                        void* pUserContext );
extern void CALLBACK OnD3D9LostDevice( void* pUserContext );
extern void CALLBACK OnD3D9DestroyDevice( void* pUserContext );

bool CALLBACK IsD3D10DeviceAcceptable( UINT Adapter, UINT Output, D3D10_DRIVER_TYPE DeviceType,
                                       DXGI_FORMAT BackBufferFormat, bool bWindowed, void* pUserContext );
HRESULT CALLBACK OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
                                      void* pUserContext );
HRESULT CALLBACK OnD3D10ResizedSwapChain( ID3D10Device* pd3dDevice, IDXGISwapChain* pSwapChain,
                                          const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext );
void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext );
void CALLBACK OnD3D10ReleasingSwapChain( void* pUserContext );
void CALLBACK OnD3D10DestroyDevice( void* pUserContext );

void InitApp();
void RenderText();
void setStaticCameraPosition();
void setDynamicCameraPosition();
void flapWings(float fElapsedTime);
int randomm(int min, int max);
void onClose();
//--------------------------------------------------------------------------------------
// Entry point to the program. Initializes everything and goes into a message processing 
// loop. Idle time is used to render the scene.
//--------------------------------------------------------------------------------------
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
    // Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

    // DXUT will create and use the best device (either D3D9 or D3D10) 
    // that is available on the system depending on which D3D callbacks are set below

    // Set DXUT callbacks
    DXUTSetCallbackMsgProc( MsgProc );
    DXUTSetCallbackKeyboard( OnKeyboard );
    DXUTSetCallbackFrameMove( OnFrameMove );
    DXUTSetCallbackDeviceChanging( ModifyDeviceSettings );

    DXUTSetCallbackD3D9DeviceAcceptable( IsD3D9DeviceAcceptable );
    DXUTSetCallbackD3D9DeviceCreated( OnD3D9CreateDevice );
    DXUTSetCallbackD3D9DeviceReset( OnD3D9ResetDevice );
    DXUTSetCallbackD3D9DeviceLost( OnD3D9LostDevice );
    DXUTSetCallbackD3D9DeviceDestroyed( OnD3D9DestroyDevice );
    DXUTSetCallbackD3D9FrameRender( OnD3D9FrameRender );

    DXUTSetCallbackD3D10DeviceAcceptable( IsD3D10DeviceAcceptable );
    DXUTSetCallbackD3D10DeviceCreated( OnD3D10CreateDevice );
    DXUTSetCallbackD3D10SwapChainResized( OnD3D10ResizedSwapChain );
    DXUTSetCallbackD3D10SwapChainReleasing( OnD3D10ReleasingSwapChain );
    DXUTSetCallbackD3D10DeviceDestroyed( OnD3D10DestroyDevice );
    DXUTSetCallbackD3D10FrameRender( OnD3D10FrameRender );

    InitApp();
    DXUTInit( true, true, NULL ); // Parse the command line, show msgboxes on error, no extra command line params
    DXUTSetCursorSettings( true, true );
    DXUTCreateWindow( L"David Sigley - 10173065" );
    DXUTCreateDevice( true, 640, 480 );
    DXUTMainLoop(); // Enter into the DXUT render loop

    //Delete things

    delete g_p_Effect;
    delete box;
    delete gameFloor;
    delete character;
    delete leftWing;
    delete rightWing;
    delete all;
    delete m_hWnd;
    //delete g_pTxtHelper;

    //delete g_pFont9;
    //delete g_pSprite9;
    //delete g_pFont10;
    //delete g_pSprite10;

    delete shoot;


    _CrtDumpMemoryLeaks();
    _CrtSetBreakAlloc(0x00823C20);


    return DXUTGetExitCode();
}


//--------------------------------------------------------------------------------------
// Initialize the app 
//--------------------------------------------------------------------------------------
void InitApp()
{
    g_SettingsDlg.Init( &g_DialogResourceManager );
    g_HUD.Init( &g_DialogResourceManager );
    g_SampleUI.Init( &g_DialogResourceManager );

    g_HUD.SetCallback( OnGUIEvent ); int iY = 10;
    g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 35, iY, 125, 22 );
    g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 35, iY += 24, 125, 22, VK_F2 );
    g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 35, iY += 24, 125, 22, VK_F3 );
    g_HUD.AddButton( IDC_TOGGLEWARP, L"Toggle WARP (F4)", 35, iY += 24, 125, 22, VK_F4 );

    g_SampleUI.SetCallback( OnGUIEvent ); iY = 10;
}


//--------------------------------------------------------------------------------------
// Render the help and statistics text. This function uses the ID3DXFont interface for 
// efficient text rendering.
//--------------------------------------------------------------------------------------
void RenderText()
{
    g_pTxtHelper->Begin();
    g_pTxtHelper->SetInsertionPos( 5, 5 );
    g_pTxtHelper->SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 0.0f, 1.0f ) );
    g_pTxtHelper->DrawTextLine( DXUTGetFrameStats( DXUTIsVsyncEnabled() ) );
    g_pTxtHelper->DrawTextLine( DXUTGetDeviceStats() );
    g_pTxtHelper->End();
}


//--------------------------------------------------------------------------------------
// Reject any D3D10 devices that aren't acceptable by returning false
//--------------------------------------------------------------------------------------
bool CALLBACK IsD3D10DeviceAcceptable( UINT Adapter, UINT Output, D3D10_DRIVER_TYPE DeviceType,
                                       DXGI_FORMAT BackBufferFormat, bool bWindowed, void* pUserContext )
{
    return true;
}


//--------------------------------------------------------------------------------------
// Create any D3D10 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
                                      void* pUserContext )
{
    HRESULT hr;

    V_RETURN( D3DX10CreateSprite( pd3dDevice, 500, &g_pSprite10 ) );
    V_RETURN( g_DialogResourceManager.OnD3D10CreateDevice( pd3dDevice ) );
    V_RETURN( g_SettingsDlg.OnD3D10CreateDevice( pd3dDevice ) );
    V_RETURN( D3DX10CreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
                                OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
                                L"Arial", &g_pFont10 ) );
    g_pTxtHelper = new CDXUTTextHelper( NULL, NULL, g_pFont10, g_pSprite10, 15 );


    //**********************************************************************//
    // We use the camera object to store the View and Projection matrices.  //
    // The projection matrix is created in OnD3D10ResizedSwapChain().       //
    // Setup the camera's view parameters here, which creates the view      //
    // matrix.                                                              //
    //**********************************************************************//

    setStaticCameraPosition();


    //**********************************************************************//
    // Create a new thing and create a shader effect and a mesh to go with  //
    // it.                                                                  //
    //**********************************************************************//

    g_p_Effect = new EffectForAbstractThing3D(pd3dDevice, L"Thing3D.fx");

    g_p_Effect->lightDirection       = D3DXVECTOR4(0, 1, -1, 1);
    g_p_Effect->lightDiffuseColour   = D3DXVECTOR4(1, 1, 1, 1);



    //**********************************************************************//
    // Create a new thing and plug the shader effect and various other stuff//
    // into it.                                                             //
    //**********************************************************************//
    //HWND hWnd;

    shoot = new Fire();
    shoot->AddAll(pd3dDevice, g_p_Effect);
    //shoot->initSound("Media\\Sounds\\fire.WAV", m_hWnd);


    gameFloor               = new Thing3D(pd3dDevice);
    gameFloor->setEffect(g_p_Effect);
    gameFloor->createMesh(L"Media\\Stolen\\TankScene.sdkmesh");
    gameFloor->setInitialDirection(0, 0, -1);
    gameFloor->setScale(50, 50, 50);
    gameFloor->moveTo(0, -50, 0);






    //thing      = new Thing3DObj(pd3dDevice);
    box      = new Thing3DObj(pd3dDevice);
    character      = new Thing3D(pd3dDevice);
    leftWing      = new Thing3D(pd3dDevice);
    rightWing      = new Thing3D(pd3dDevice);
    //all               = new AllThings(character, leftWing, rightWing);
    all             = new AllThings();


    all->body = character;
    //all->bodyObj = box;
    all->leftWing = leftWing;
    all->rightWing = rightWing;

    character->setEffect(g_p_Effect);
    character->createMesh(L"Media\\Tiger\\tiger.sdkmesh");
    character->setInitialDirection(0, 0, -1);
    character->setScale(1, 1, 1);
    character->setGravity(true);
    character->rotateBy(0, 3.14, 0);


    box->setEffect(g_p_Effect);
    box->createMesh(L"Media\\\Stolen\\Box\\WoodenBoxOpen02.obj");
    //box->createMesh(L"Media\\\wateringcan_obj\\wcan.obj");
    box->setInitialDirection(0, 0, -1);
    box->setScale(1, 1, 1);
    //box->setGravity(true);

    leftWing->setEffect(g_p_Effect);
    leftWing->createMesh(L"Media\\Wing\\wing.sdkmesh");
    leftWing->setInitialDirection(0, 0, -1);
    leftWing->setScale(1, 1, 1);

    rightWing->setEffect(g_p_Effect);
    rightWing->createMesh(L"Media\\Wing\\wing.sdkmesh");
    rightWing->setInitialDirection(0, 0, -1);
    rightWing->setScale(1, 1, 1);


    return S_OK;
}




//**************************************************************************//
// Create any D3D10 resources that depend on the back buffer.  This         //
// includes creating the projection matrix, which is stored in the camera.  //
//**************************************************************************//

HRESULT CALLBACK OnD3D10ResizedSwapChain( ID3D10Device* pd3dDevice, IDXGISwapChain* pSwapChain,
                                          const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
    HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D10ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );
    V_RETURN( g_SettingsDlg.OnD3D10ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );






    float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height;
    g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 0.1f, 1000.0f );
   // g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
    //g_Camera.SetButtonMasks( MOUSE_LEFT_BUTTON, MOUSE_WHEEL, MOUSE_MIDDLE_BUTTON );



    g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
    g_HUD.SetSize( 170, 170 );
    g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300 );
    g_SampleUI.SetSize( 170, 300 );

    return S_OK;
}






void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    D3DXMATRIX matWorld;
    D3DXMATRIX matView;
    D3DXMATRIX matProjection;

    float ClearColor[4] = { 0.176f, 0.196f, 0.667f, 0.0f };
    ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
    pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );

    // Clear the depth stencil
    ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
    pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );

    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }




    //Text Render constants (set to display text in the middle of the screen
    RECT r;
r.top = 100;
r.bottom = 600;
r.left = 70;
r.right = 700;
HRESULT hr;

    if (boxTimer < 0){
           int No = boxTimer;
            std::wstringstream StrStream;
            StrStream << L"\n\n\n\n\n\nGame Over, better luck next time!!\n " << L"\nYou Collected " << boxCount << " Box(es) \n\n\n Press Return to try again or esc to quit";
            std::wstring messageString = StrStream.str();

            hr = g_pSprite10->Begin(0);
            hr = g_pFont10->DrawTextW(g_pSprite10, messageString.c_str(), -1, &r, DT_LEFT | DT_TOP, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f));
            //hr = sprite->Flush();
            hr = g_pSprite10->End();
            pd3dDevice->OMSetBlendState(NULL, 0, 0xffffffff);
            return;
    }

    if(startScreen){

            hr = g_pSprite10->Begin(0);
            std::wstring left = L"\nWelcome to my game \n\nJerry is just a typical flying tiger who loves smashing boxes .. \noh, and shoots mini tigers out his mouth\n\n The aim of this game is to smash as many boxes as you can within the time limit. \n Don't forget to keep an eye on the time, because the more boxes you smash, the less time\n you will get between boxes \n\n\n\n Controls:\n S = up. W = Down. Q = Left. E = Right\n A = Rotate Left. D = Rotate Right\n Space Bar = Fire. Left Shift = Fly Forward.\n\n\n\n Press Return to begin!!";
            //hr = g_pFont10->DrawTextW(g_pSprite10, left.c_str(), -1, &r, DT_LEFT | DT_TOP | DT_CALCRECT, D3DXCOLOR(0.0f, 1.0f, 4.0f, 1.0f));
            hr = g_pFont10->DrawTextW(g_pSprite10, left.c_str(), -1, &r, DT_LEFT | DT_TOP, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f));
            hr = g_pFont10->DrawTextW(g_pSprite10, left.c_str(), -1, &r, DT_LEFT | DT_TOP, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f));
            //hr = sprite->Flush();
            hr = g_pSprite10->End();
            pd3dDevice->OMSetBlendState(NULL, 0, 0xffffffff);
            return;
    }





    //**********************************************************************//
    // Get the projection & view matrix, which are now hidden in the the    //
    // camera class.                                                        //
    //**********************************************************************//

    matProjection = *g_Camera.GetProjMatrix();
    matView       = *g_Camera.GetViewMatrix();
    //matProjection = g_cam.getProjectionMatrix();
    //matView       = g_cam.getViewMatrix();

    //**********************************************************************//
    // Pass the light direction and colour to the shader.  It seems silly   //
    // to do this every frame, but I suppose the light might have moved..   //
    //**********************************************************************//

    g_p_Effect->pLightDirectionInShader->SetFloatVector(       (float *) &g_p_Effect->lightDirection);
    g_p_Effect->pLightDiffuseColourInShader->SetFloatVector(   (float *) &g_p_Effect->lightDiffuseColour);



    //**********************************************************************//
    //  Perform Game Logic                                                  //  
    //**********************************************************************//
    if (boxCount >= 0) difficulty = 16;
    if (boxCount >= 5) difficulty = 11;
    if (boxCount >= 10) difficulty = 6;


    if ((!character->intersectsWith(box)) && (!shoot->intersectsWith(box))) {

    box->matView       = matView;
    box->matProjection = matProjection;

    box->render();

    } else {
        //Call axploding box.

        //increment count and display it
            box->moveTo(randomm(1, 30), randomm(1, 30), randomm(1, 30));

        // reset box in another place and reset timer.
            boxTimer = difficulty;
            boxCount++;
    }


    //**********************************************************************//
    // Render the thing3D.                                                  //
    // Note, the Thing3D creates its own world matrix.  But it needs to know//
    // the other matrices to pass to its own shader.                        //
    //**********************************************************************//



        if(fire){
            if(frameCount < 50){
        shoot->Shoot(character->returnWorldMatrix(), matView, matProjection);

        frameCount++;
            } else {
                fire = false; frameCount = 0;
            }
        }

    gameFloor->matView       = matView;
    gameFloor->matProjection = matProjection;
    gameFloor->render();
    character->matView       = matView;
    character->matProjection = matProjection;
    leftWing->matView       = matView;
    leftWing->matProjection = matProjection;
    rightWing->matView       = matView;
    rightWing->matProjection = matProjection;


    //**********************************************************************//
    // Render the thing if the camera isn't on it, otherwise get a tiger's  //
    // eye view of the world.                                               //
    //**********************************************************************//

    //flap wings


    if (!g_b_CameraOnThing) {
        all->render();
        //setStaticCameraPosition();



        D3DXVECTOR3 viewerPos;

        viewerPos.x = character->x;   viewerPos.y = character->y;
        viewerPos.z = character->z;



        D3DXVECTOR3 newDir, newDirNorm, lookAtPoint( 0.0f, 1.0f, 5.0f  );
        D3DXVec3TransformCoord(&newDir, &lookAtPoint,
                &character->matWorld);



        D3DXVec3Normalize(&newDirNorm, &newDir);

        D3DXVECTOR3             vecEye = newDir;
        D3DXVECTOR3             vecAt = viewerPos;


        g_Camera.SetViewParams ( &vecEye, &vecAt);
        // Set the Camera parameters
        g_Camera.SetProjParams ( D3DX_PI/4, 5.5, 30.0f, 30.0f);
        g_Camera.SetResetCursorAfterMove ( true);
        g_Camera.FrameMove(fElapsedTime);

    }
    else
    {
        all->render();
        //setDynamicCameraPosition();
        g_Camera.FrameMove(fElapsedTime);
    }



    boxTimer -= fElapsedTime;

    //****************************************************************************//
    // Box timer - This calculates and displays a count down from 10              //
    //****************************************************************************//


   int No = boxTimer;  // Or you can use float No = 10.5f
   std::wstringstream StrStream;
    hr = g_pSprite10->Begin(0);

   StrStream << L"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nTime Remaining - " << No << L"\n\nBoxes Collected - " << boxCount;
   std::wstring messageString = StrStream.str();

        //hr = g_pFont10->DrawTextW(g_pSprite10, left.c_str(), -1, &r, DT_LEFT | DT_TOP | DT_CALCRECT, D3DXCOLOR(0.0f, 1.0f, 4.0f, 1.0f));
        hr = g_pFont10->DrawTextW(g_pSprite10, messageString.c_str(), -1, &r, DT_LEFT | DT_TOP, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f));
        //hr = sprite->Flush();
        hr = g_pSprite10->End();
        pd3dDevice->OMSetBlendState(NULL, 0, 0xffffffff);

    //****************************************************************************//
    // And finally, render the DXUT buttons and the thing which grandly calls     //
    // itself a HUD (Head Up Display).                                            //
    //****************************************************************************//

    DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
    RenderText();
    g_HUD.OnRender( fElapsedTime );
    g_SampleUI.OnRender( fElapsedTime );
    DXUT_EndPerfEvent();

    }


//--------------------------------------------------------------------------------------
// Release D3D10 resources created in OnD3D10ResizedSwapChain 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10ReleasingSwapChain( void* pUserContext )
{
    g_DialogResourceManager.OnD3D10ReleasingSwapChain();
}


//--------------------------------------------------------------------------------------
// Release D3D10 resources created in OnD3D10CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10DestroyDevice( void* pUserContext )
{
    g_DialogResourceManager.OnD3D10DestroyDevice();
    g_SettingsDlg.OnD3D10DestroyDevice();
    SAFE_RELEASE( g_pFont10 );
    SAFE_RELEASE( g_pEffect10 );
    SAFE_RELEASE( g_pVERTEXLayout );
    SAFE_RELEASE( g_pSprite10 );
    SAFE_DELETE( g_pTxtHelper );
    SAFE_DELETE( g_pTxtHelper );


    SAFE_DELETE( g_pmWorldViewProj );
    SAFE_DELETE( g_pmWorld );
    SAFE_DELETE( g_pfTime );
    SAFE_RELEASE( m_font );


}


//--------------------------------------------------------------------------------------
// Called right before creating a D3D9 or D3D10 device, allowing the app to modify the device settings as needed
//--------------------------------------------------------------------------------------
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext )
{
    if( pDeviceSettings->ver == DXUT_D3D9_DEVICE )
    {
        IDirect3D9* pD3D = DXUTGetD3D9Object();
        D3DCAPS9 Caps;
        pD3D->GetDeviceCaps( pDeviceSettings->d3d9.AdapterOrdinal, pDeviceSettings->d3d9.DeviceType, &Caps );

        // If device doesn't support HW T&L or doesn't support 1.1 VERTEX shaders in HW 
        // then switch to SWVP.
        if( ( Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) == 0 ||
            Caps.VertexShaderVersion < D3DVS_VERSION( 1, 1 ) )
        {
            pDeviceSettings->d3d9.BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
        }

        // Debugging VERTEX shaders requires either REF or software VERTEX processing 
        // and debugging pixel shaders requires REF.  
#ifdef DEBUG_VS
        if( pDeviceSettings->d3d9.DeviceType != D3DDEVTYPE_REF )
        {
            pDeviceSettings->d3d9.BehaviorFlags &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;
            pDeviceSettings->d3d9.BehaviorFlags &= ~D3DCREATE_PUREDEVICE;
            pDeviceSettings->d3d9.BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
        }
#endif
#ifdef DEBUG_PS
        pDeviceSettings->d3d9.DeviceType = D3DDEVTYPE_REF;
#endif
    }

    // For the first device created if its a REF device, optionally display a warning dialog box
    static bool s_bFirstTime = true;
    if( s_bFirstTime )
    {
        s_bFirstTime = false;
        if( ( DXUT_D3D9_DEVICE == pDeviceSettings->ver && pDeviceSettings->d3d9.DeviceType == D3DDEVTYPE_REF ) ||
            ( DXUT_D3D10_DEVICE == pDeviceSettings->ver &&
              pDeviceSettings->d3d10.DriverType == D3D10_DRIVER_TYPE_REFERENCE ) )
            DXUTDisplaySwitchingToREFWarning( pDeviceSettings->ver );
    }

    return true;
}
share|improve this question

closed as too localized by Josh Petrie, Byte56, ashes999, Jari Komppa, doppelgreener Aug 23 '12 at 0:24

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Note: I have omitted a few methods due to size restrictions on posting in this site. –  David Aug 20 '12 at 0:54
5  
Use a memory leak tool. No one is going to answer this. Also note that your program might just allocate memory. But then keeps it instead of returning it to the os. It doesn't necessarily mean it's a memory leak. –  Sidar Aug 20 '12 at 1:30
2  
This is way too localized a question. –  Josh Petrie Aug 20 '12 at 1:54

1 Answer 1

You got this code in main function:

//Delete things

delete g_p_Effect;
delete box;
delete gameFloor;
delete character;
delete leftWing;
delete rightWing;
delete all;
delete m_hWnd;
//delete g_pTxtHelper;

//delete g_pFont9;
//delete g_pSprite9;
//delete g_pFont10;
//delete g_pSprite10;

delete shoot;

some of them should be in DXUTSetCallbackD3D9DeviceDestroyed() or DXUTSetCallbackD3D9DeviceLost() or DXUTSetCallbackD3D10SwapChainReleasing() or DXUTSetCallbackD3D10DeviceDestroyed(), because you are allocating memory in Create/Reset functions and these functions are called many times.

Anyway, instead of SAFE_DELETE( g_pfTime ); it should by SAFE_RELEASE( g_pfTime );, I think, there is a lot of similar errors.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.