Sign in to follow this  

Distorted screen shows up after my app closes...

This topic is 4806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this