Sign in to follow this  

game ending itself problem...help?

This topic is 3150 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

As you start off in screen one of my zeldaish game, and you move to screen 2, and then back to screen one for any reason, the game suddenly ends...D: heres the game: zipped game (requires the SDL.dll included) just walk through the opening on the right then back to the left, the program ends... heres the specific code I think may have something to do with it...but im not sure:
..........
..........
 //avatar position X/Y
 int avX, avY;
 //map stats
 const int NumScrWide=5;
 const int NumScrHigh=5;
..........
..........
int main(int args, char *argv[]){
     
     screen(1000, 500, 0, "Tileset Simulation");
     int x = w / 2, y = h-20 ;
     int avatarX=x;
     int avatarY=h/2;
     //screen selector
     int screen=1;
     
     while(!done()){
     .....
     avX=getAvatarX(avatarX,avatarY);
     avY=getAvatarY(avatarX,avatarY);
     avatarX=avX;
     avatarY=avY;
     .....
     screenTester(screen,avatarX,avatarY);
     drawAvatar(avX,avY);
     .....
     .....
     .....
     }




heres the actual screens at least the parts I think are maybe the problem:
else if(screen==1){
          grass();
          
          //left wall
          drawNoPassRect(avX,avY,enemyX,enemyY,0,0,5,h-1,RGB_Red);
          for(int i=0;i<=h;i+=10){
                  drawRect(0,i,5,i+2,RGB_Black);
                  }
          //top wall
          drawNoPassRect(avX,avY,enemyX,enemyY,0,0,w-1,5,RGB_Red);
          for(int i=0;i<=w;i+=10){
                  drawRect(i,0,i+2,5,RGB_Black);
                  }
          //right wall
          drawNoPassRect(avX,avY,enemyX,enemyY,w-5,0,w-1,h-100,RGB_Red);
          drawNoPassRect(avX,avY,enemyX,enemyY,w-5,h-50,w-1,h-1,RGB_Red);
          for(int i=0;i<=h-100;i+=10){
                  drawRect(w-5,i,w-1,i+2,RGB_Black);
                  }
          for(int i=h-50;i<=h-1;i+=10){
                  drawRect(w-5,i,w-1,i+2,RGB_Black);
                  }
          //bottom trees
                   //left
          for(int i=w/2-65;i>=0;i-=50){
                  drawDisk(i,h-15,30,RGB_Darkgreen);
                  } 
          for(int i=w/2-65;i>=0;i-=50){
                  drawDisk(i,h-15,20,RGB_Olive);
                  } 
          for(int i=w/2-65;i>=0;i-=50){
                  drawDisk(i,h-15,10,RGB_Darkgreen);
                  }
                  //right
          for(int i=w/2+65;i<=w;i+=50){
                  drawDisk(i,h-15,30,RGB_Darkgreen);
                  } 
          for(int i=w/2+65;i<=w;i+=50){
                  drawDisk(i,h-15,20,RGB_Olive);
                  } 
          for(int i=w/2+65;i<=w;i+=50){
                  drawDisk(i,h-15,10,RGB_Darkgreen);
                  }
                  //border control
                  drawNoPassRect(avX,avY,enemyX,enemyY,0,h-40,w/2-45,h);
                  drawNoPassRect(avX,avY,enemyX,enemyY,w/2+45,h-40,w,h);
          
          //draw boulder and check if near
          if(drawNoPassRect(avX,avY,enemyX,enemyY,w-95,50,w-50,75,RGB_Gray)==true){nearBoulderLvl[1]=true;}
          else {nearBoulderLvl[1]=false;}
                  
                  //boulder menu
                  if(nearBoulderLvl[1]==true)
                  {
                      menuMakerObjects(keyLvl[1],"Look under boulder?","You found a key!","numKeys",numKeys);
                  }
                  
                 //draw house and
                 //check if near house
                 if(drawHouse(avX,avY,50,50)==true)
                 {
                  nearHouseLvl[1]=true;
                 }else{nearHouseLvl[1]=false;}
                 
                 //house menu    
                 if(nearHouseLvl[1]==true)
                 {
                                         
                 menuMakerDoors("Enter the house?",screen,-1,1,"You need the key!",avX,avY);
          }
        
}

else if(screen==2){
                   .....
                   .....        
                 createEnemy(1,"rabbit",600,200,EnemyX[1],EnemyY[1],numKeys);                                                               
                            
}



and heres the actual changing of the screens:
//actual level changing
          if(avX>w){
                avX=1;
                screen++;     
                     }
          else if(avX<0){
               avX=w;
                screen--;
               }
          else if(avY>h){
               avY=1;
               screen+=NumScrWide;
               }
          else if(avY<0){
               avY=h;
               screen-=NumScrHigh;
               }
               //    



The last two code blocks are both a part of ScreenTester(...) sorry if I cant be more clear on the question...

Share this post


Link to post
Share on other sites
but it only happens when I leave in an enemy call...if I comment it out it switches fine.

also even with the enemy call it switches fine for every other screen,
just 1--->2--->1 gives the problem.

heres the jist:

1 2 3 4 5


6 7 8 9 10


11...

5x5 map

if you go from one to two, then back to one, it ends the program
nothing else has a problem

Share this post


Link to post
Share on other sites
I can't off hand see anything that would crash your app. It still sounds like memory thing.

What compiler are you using? This is what a debugger is for. If you are on windows, get visual C++ express (its free) and use its debugger. The great thing about it that it tells you where it crashed, why it crashed and you can view the values of your variables at the time of the crash. This help you in identifying the issue like you wouldn't believe.

Share this post


Link to post
Share on other sites
Im using dev++ as of now for this project because I cannot get express to work with a SDL project..super complicated...): is there a way I can move a project from dev over to express with the settings saved? so I dont have to mess with the linker or anything?

Share this post


Link to post
Share on other sites
You're gonna have to start a new project and do everything yourself.

As a former dev-c++er, I know the switch is a little hard at first. But once you get it down you will never look back. Have you followed the tutorial on http://cone3d.gamedev.net ?

Share this post


Link to post
Share on other sites
I went throught the lazyfoo tut again and im closer than ive ever been!

everything is actually compiling, I just get this linker error:

>main.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: bool __thiscall std::_Tree<class std::_Tmap_traits<int,bool,struct std::less<int>,class std::allocator<struct std::pair<int const ,bool> >,0> >::const_iterator::operator==(class std::_Tree<class std::_Tmap_traits<int,bool,struct std::less<int>,class std::allocator<struct std::pair<int const ,bool> >,0> >::const_iterator const &)const " (??8const_iterator@?$_Tree@V?$_Tmap_traits@H_NU?$less@H@std@@V?$allocator@U?$pair@$$CBH_N@std@@@2@$0A@@std@@@std@@QBE_NABV012@@Z)

1>C:\Users\Logan Henson\Documents\Visual Studio 2008\Projects\Learning\Practice\Debug\SDLproject.exe : fatal error LNK1120: 1 unresolved externals

wha???????????

and in release mode i get this:

1>Linking...
1>main.obj : error LNK2001: unresolved external symbol _SDL_UpdateRect
1>main.obj : error LNK2001: unresolved external symbol _SDL_mutexV
1>main.obj : error LNK2001: unresolved external symbol _SDL_Init
1>main.obj : error LNK2001: unresolved external symbol _SDL_SetVideoMode
1>main.obj : error LNK2001: unresolved external symbol _SDL_DestroyMutex
1>main.obj : error LNK2001: unresolved external symbol _SDL_FillRect
1>main.obj : error LNK2001: unresolved external symbol _SDL_mutexP
1>main.obj : error LNK2001: unresolved external symbol _SDL_WM_SetCaption
1>main.obj : error LNK2001: unresolved external symbol _SDL_PollEvent
1>main.obj : error LNK2001: unresolved external symbol _SDL_EnableUNICODE
1>main.obj : error LNK2001: unresolved external symbol _SDL_GetMouseState
1>main.obj : error LNK2001: unresolved external symbol _SDL_PauseAudio
1>main.obj : error LNK2001: unresolved external symbol _SDL_GetRGB
1>main.obj : error LNK2001: unresolved external symbol _SDL_CloseAudio
1>main.obj : error LNK2001: unresolved external symbol _SDL_OpenAudio
1>main.obj : error LNK2001: unresolved external symbol _SDL_Delay
1>main.obj : error LNK2001: unresolved external symbol _SDL_LockSurface
1>main.obj : error LNK2001: unresolved external symbol _SDL_UnlockSurface
1>main.obj : error LNK2001: unresolved external symbol _SDL_CreateMutex
1>main.obj : error LNK2001: unresolved external symbol _SDL_GetTicks
1>main.obj : error LNK2001: unresolved external symbol _SDL_GetError
1>main.obj : error LNK2001: unresolved external symbol _SDL_MapRGB
1>main.obj : error LNK2001: unresolved external symbol _SDL_GetKeyState
1>main.obj : error LNK2001: unresolved external symbol _SDL_Quit
1>MSVCRT.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
1>C:\Users\Logan Henson\Documents\Visual Studio 2008\Projects\Learning\Practice\Release\SDLproject.exe : fatal error LNK1120: 25 unresolved externals
1>Build log was saved at "file://c:\Users\Logan Henson\Documents\Visual Studio 2008\Projects\Learning\Practice\SDLproject\Release\BuildLog.htm"
1>SDLproject - 26 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites
Go to Project-> [project name] properties -> linker -> input
Make sure you have the following in your "additional dependencies" box: SDL.lib SDLMain.lib

Share this post


Link to post
Share on other sites
It works!
Thank you so so much!
You have just made my life ALOT easier and better (:

I have had nothing but good experiences with this site and the people on it!

one last thing though,

It works great in release mode, but in debug mode I am still getting a linker error:

1>main.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: bool __thiscall std::_Tree<class std::_Tmap_traits<int,bool,struct std::less<int>,class std::allocator<struct std::pair<int const ,bool> >,0> >::const_iterator::operator==(class std::_Tree<class std::_Tmap_traits<int,bool,struct std::less<int>,class std::allocator<struct std::pair<int const ,bool> >,0> >::const_iterator const &)const " (??8const_iterator@?$_Tree@V?$_Tmap_traits@H_NU?$less@H@std@@V?$allocator@U?$pair@$$CBH_N@std@@@2@$0A@@std@@@std@@QBE_NABV012@@Z)

1>C:\Users\Logan Henson\Documents\Visual Studio 2008\Projects\Learning\Practice\Debug\SDLproject.exe : fatal error LNK1120: 1 unresolved externals

should I just stick to release mode and Itll be fine?
or is there a way to fix this?

Share this post


Link to post
Share on other sites
I can't find much else on it. Are you sure you followed the tutorial from lazyfoo to the letter?

edit: The cone3d tutorial is really outdated, but nothing major has changed in SDL since it was written.

Share this post


Link to post
Share on other sites
I'm afraid I can't help you with your IDE issues, but for tracking down your initial problem, there's two good ways to do it. The first is to insert print statements throughout your code so you know what it's doing right before it crashes. For example, if your code looks something like this:

init()
while 1 {
update()
draw()
}


then you could add this:

print "Initializing\n"
init()
print "Done initializing\n"
while 1 {
print "Updating\n"
update()
print "Drawing\n"
draw()
}

Then, if you found that the last print statement before the game crashes is "Updating", you know that the problem is somewhere in the update() function. So you go to that function and add print statements there. Of course your print statements can also output the values of variables or anything else you think is handy. This lets you narrow things down until you know why your game is crashing.

The second approach is to learn to use a debugger, and then to set breakpoints in your program so you can step through its operation and see what's going on at the point of crash. That's harder to describe in a post, though. :) Still, both skills are important to have and I recommend trying both to see which you favor. Debuggers can make the process very straightforward once you know how to use them, but they aren't always available (for example, high-level scripting languages tend to not have debuggers).

Share this post


Link to post
Share on other sites
What is the runtime library when you are in debug mode?

You can find it under:

Properties -> Configuration properties -> C/C++ -> Code Generation -> Runtime library

This property will typically be "Multi-threaded DLL (/MD)" in release mode, and "Multi-threaded Debug DLL (/MDd)" when in debug mode.

edit:
Also check the preprocessor definitions under Properties -> Configuration properties -> C/C++ -> Preprocessor.

It should contain _DEBUG when in debug mode, and NDEBUG when in release mode.

Share this post


Link to post
Share on other sites
thanks pulpfist!

they were both in release mode for sum reason...

everything works now!

one last question haha:

Is it an option to move my project and its settings from my computer in vc++
to another computers vc++? like can you just use like a flash drive and drag and drop projects from the same program between computers?

Share this post


Link to post
Share on other sites
Quote:
Original post by BlueBan007
Is it an option to move my project and its settings from my computer in vc++
to another computers vc++? like can you just use like a flash drive and drag and drop projects from the same program between computers?


Generally you can do just that. Make sure you get all the project files too and you should be able to move it wherever you want to with settings intact!

Share this post


Link to post
Share on other sites

This topic is 3150 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