Archived

This topic is now archived and is closed to further replies.

Fallen_Angel

A few problems with my first game.

Recommended Posts

Fallen_Angel    138
I''ve just started game programming and begun working on my first game, a basic 2 player tank game. I''ve come across two problems so far and can''t find a solution to them. The first is to do with a menu screen at the start of the game, where you press a certain key for different screens. It used to work fine until I added a midi for background music. If you try to quit it makes the program crashes, however if you play the game first you can quit normally. The other problem is when playing the game. If just one player fires at the other, everything seems to work fine, yet if both players fire at each other at the same time, strange things seem to happen. Sometimes the collision between missiles and tanks aren''t registered but most of the time the game tends to end early, after each tank has been shot 6-7 times when they''re meant to have a health of 10. It was all written in MSVC++ 6.0 with the DirectX7a library and on win98 with DirectX8.0 installed if this helps. I''ve got the executable plus the source code on my webpage: http://www.angelfire.com/realm/fap/ Any help would be appreciated. Thanks.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
"It used to work fine until I added a midi for background music. If you try to quit it makes the program crashes, however if you play the game first you can quit normally...."



so where does the program crash? didnt you compile the game in debug mode?

Share this post


Link to post
Share on other sites
Fallen_Angel    138
When you start the game you come to a main menu where you can press ''T'' to start a two-player game, ''C'' to see the commands and ''Q'' to quit. Running the game and pressing ''Q'' straight away makes the program exit with an error, whilst starting a game with ''T'', finishing it and returning to the menu then pressing ''Q'' to quit makes the program exit fine without any errors.

Hope this helps.

Share this post


Link to post
Share on other sites
Sandman    2210
My guess is that your music system is allocating memory/dx objects once the game starts, and this memory is being freed unconditionally when you exit. Normally this is fine, but if you exit as soon as the program starts, the program tries to free non-existent memory causing a crash.

Make sure that all pointers are initialised to NULL before you use them. Make sure all dx objects actually exist before releasing them.

Edited by - Sandman on August 1, 2001 8:12:46 AM

Share this post


Link to post
Share on other sites
Sandman    2210
Having quickly glanced through your code, I think I can see the problem.

My initial guess was right - you are unconditionally releasing objects which dont exist in your destructor:

  
CDirectMidi::~CDirectMidi() {
if(!m_bInitialized) //Exit if not ready.

return;
stop(); //Stop music.

m_pMIDIsegment->SetParam(GUID_Unload, -1, 0, 0, (void*)m_pPerformance); //Unload instruments.

m_pMIDIsegment->Release(); //Release the segment.

m_pPerformance->CloseDown(); //Close down the performance object.

m_pPerformance->Release(); //Release the performance object.

m_pLoader->Release(); //Release the loader object.

CoUninitialize(); //Release COM

} //End destructor.



the m_pMIDIsegment is NULL unless the load method has been called - but this method is not called until you reach the game phase. You need to check this pointer in the destructor.

  
CDirectMidi::~CDirectMidi() {
if(!m_bInitialized) //Exit if not ready.

return;
stop(); //Stop music.

if(m_pMIDIsegment)
{
m_pMIDIsegment->SetParam(GUID_Unload, -1, 0, 0, (void*)m_pPerformance); //Unload instruments.

m_pMIDIsegment->Release(); //Release the segment.

}
m_pPerformance->CloseDown(); //Close down the performance object.

m_pPerformance->Release(); //Release the performance object.

m_pLoader->Release(); //Release the loader object.

CoUninitialize(); //Release COM

} //End destructor


Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
cool, but running your game in debug-mode would have told you this,too ( i don''t think that Sandman is a bad programmer, i just think that the compiler would be faster :-) :-) )


so did you solve your other problem already?

p.s. sorry for posting as anonymous poster

Share this post


Link to post
Share on other sites
Fallen_Angel    138
Nah, haven''t fixed the other problem yet. Haven''t really had time to work on it yet...been snowed under with university unfortunately.

I''ve manged to isolate the problem to an extent, it occurs whenever there is more than missile being fired. When something happens to one of them, either exploding on a wall or colliding with a tank, that event happens to every missile on the screen.

I''m guessing that this error is in the Objman.cpp file if this helps but i still can''t find where it''s going wrong, and knowing any of my programs it''ll be just one or two simple lines of code that will be obvious once it''s found.

Thanks again for any help that is offered.

Share this post


Link to post
Share on other sites