Distorted screen shows up after my app closes...

Started by
4 comments, last by xegoth 19 years, 6 months ago
This is a weird (and bad) bug. My game runs fine it's written in c++ and DX 9.0c, but if after I run it.. If I run something like a java game, my entire screen gets covered in a garbaged up image of my game. Obviously I'm not cleaning up after myself properly, but I'm not sure what it is. Here's my cleanup code:


DXEngine::~DXEngine()
{
	//Game finished, so destroy game objects
	LogInfo("<br>Finish Game:");

	SafeRelease(m_pD3DDevice);
	SafeRelease(m_pD3D);
	SafeRelease(m_pVertexBuffer);
	SafeRelease(m_pd3dxSprite);

	// Delete Mesh's
	SafeDelete(m_pEarth);

	//Game finished, so save statistics to log
	DWORD dwDuration = (m_dwEndTime - m_dwStartTime) / 1000;
	
	if((dwDuration != 0)&&(m_dwFrames != 0))
	{
		//Log stats
		LogInfo("<br>Statistics:");
		LogInfo("<li>Start Time (ms): %d", m_dwStartTime);
		LogInfo("<li>End Time (ms): %d", m_dwEndTime);
		LogInfo("<li>Duration (s): %d", dwDuration);
		LogInfo("<li>Total Frame Count: %d", m_dwFrames);
		LogInfo("<li>Average FPS: %d", (m_dwFrames / dwDuration));
		LogInfo("<li>Total Polygons: %d", m_dwTotalPolygons);
		LogInfo("<li>Average Polygons per Frame: %d", (m_dwTotalPolygons / m_dwFrames));
	}
	else
	{
		LogInfo("<br>No statistics to report");
	}

	StopLogging();
}


Here's my engine class:

class DXEngine : public CBase
{
public:
	DXEngine();
	virtual ~DXEngine();
	
	////////////////////////////////////////////////
	// Global functions
	bool Initialise(HINSTANCE hInst, HWND hWnd, UINT nWidth, UINT nHeight);
	void MessageLoop();
	//LPDIRECT3DDEVICE9 GetDevice();

	///////////////////////////////////////////////
	// Meshes
	CMesh* m_pEarth;

	///////////////////////////////////////////////
	// Fonts
	FontEngine m_font;

private:

	////////////////////////////////////////////
	// DirectX Variables
	LPDIRECT3D9 m_pD3D;
	LPDIRECT3DDEVICE9 m_pD3DDevice;
	D3DPRESENT_PARAMETERS m_pParameters;
	LPD3DXSPRITE m_pd3dxSprite; // Interface to Sprite routines
	LPDIRECT3DVERTEXBUFFER9 m_pVertexBuffer; // The vertex buffer

	LPDIRECT3DTEXTURE9 m_pTexShip;
	LPDIRECT3DTEXTURE9 m_pTexStars;
	
	DWORD m_dwFrames;
	DWORD m_dwStartTime;
	DWORD m_dwEndTime;
	DWORD m_dwTotalPolygons;
	DWORD m_word;

	//////////////////////////////////////////////
	// 3d Graphics functions
	bool InitialiseLights();
	D3DFORMAT CheckDisplayMode(UINT nWidth, UINT nHeight, UINT nDepth);;
	bool InitialiseD3D(HWND hWnd, UINT nWidth, UINT nHeight);
	HRESULT InitialiseVertexBuffer();
	bool InitialiseGame();
	void Render();
	void SetupCamera();
	void RenderEarth();
	void CreateExplosion(D3DXVECTOR3 location);

	// Particle systems
	ParticleSys m_explosion1;
	ParticleSys m_explosion2;

	///////////////////////////////////////////////
	// 2d Graphics functions
	HRESULT BltSprite( D3DXMATRIX matWorld, LPDIRECT3DTEXTURE9 pSrcTexture, RECT *pSrcRect, DWORD dwFlags );
	LPDIRECT3DTEXTURE9 LoadTexture(char *filename);

	HRESULT Draw2d(LPDIRECT3DTEXTURE9 pSrcTexture, RECT *pSrcRect, D3DXVECTOR3 trans, float scale, DWORD dwFlags );

	void DrawShip(SPACESHIP player);
	void DrawBullets(BULLETSET bullets);
	void DrawBackground();
	void DrawLives();
	void DrawLoser();
	void DrawCountDown();
	
	//////////////////////////////////////////////
	// Direct Input
	DXInput Input;
	void ProcessKBInput();

	//////////////////////////////////////////////
	// Timer class
	Timer Timer;


	////////////////////////////////////////////
	// Gameplay Variables
	GameModes gameMode;
	SPACESHIP m_player1;
	SPACESHIP m_player2;

	BULLETSET m_player1Bullets;
	BULLETSET m_player2Bullets;


	// Global class
	GLOBALS global;

	///////////////////////////////////////////////
	// Gameplay Functions
	void NewGame();
	void GameMain();

	//void ProcessKBInput();
	void HandleObjects();
	void MoveBullets();
	void BulletCollisionDetect();

	// MikHaven - mikhaven@hotmail.com
	float MenuCursorX;
	float MenuCursorY;
	LPDIRECT3DTEXTURE9 m_pTexMenu;
	LPDIRECT3DTEXTURE9 m_pTexStart;
	LPDIRECT3DTEXTURE9 m_pTexExit;
	GameStates state;
	void InitialiseMenu();
	void ProcessKBMenu();
	void RenderMenu();
	///////////////////////////////////
};


I'm obviously not cleaning up something proplerly, anyone know what?
Advertisement
You should release your objects in the reverse order that you created them so:

Release in this order

<Sprites, vbs, etc.>, then D3DDevice and last D3D...

I hope that will fix it
Read the section on Debugging in the Forum FAQ. If you're not cleaning up properly it will tell you.
Stay Casual,KenDrunken Hyena
my debugger says: Direct3D9: (ERROR) :Total Memory Unfreed From Current Process = 52952 bytes

How do I track down what isn't being freed?
Try reading about memory; specifically allocation and deallocation. Basically what you have is a memory leak if im not mistaken; or you could use something like mmgr to override your new and delete commands and it should take care of it for you and give you information where its leaking.
Is mmgr something I can download for free? Where do I get it? I'm using microsoft visual studio .net 2003

This topic is closed to new replies.

Advertisement