This problem occurs in the same place at a seemingly random times. Let me run this by some of you and let me know if there's a problem with my method:
I have a main menu function that resets the screen with dbSetDisplayMode(..). (I am using my desktop resolution in all cases)
I load my "main menu GUI".
I set my variables to use the GUI.
I do the dbSync loop and show/handle input for my GUI.
The first time I go into the game, it runs fine.... I click [New Game] and follow the normal method for creating a single player game.
This takes me to the main part of the game. At this point, the resolution is changed using dbSetDisplayMode(..) (again using default desktop res). I go through loading all the images, objects, and the in-game GUI. Up to this point, everything works as expected. I've used this method before, so no surprises.
Pressing [ESC], I bring up the in-game main menu and select [Exit To Main] button. This causes the program to unload all the images, objects, and the in-game GUI, and with a "goto" I jump back to the beginning of my code, taking me back to the main menu.
It show up fine, and sometimes I can go in and out multiple times before I get a problem (using EXACTLY the same method as before).
So I use debug.... I get the following error when it finally occurs:
Quote: "Unhandled exception at 0x76ef15de in Star Test.exe: 0xC0000005: Access violation reading location 0x160f4ff0."
I look at the variables on that line, and they are fine. They all show up as having the correct numbers and NOTHING has a NULL pointer..... What's going on? If you need the entire code, I'll post it. For now, here is a chunk. This is where it crashed:
while (!EnterGame){
if (MainGUI.MenuItem[ExitGameButton].State>0){
NetDisconnect();
return false;//this MUST be here for the return to work....
}
MainGUI.ShowGUI();
if (MainGUI.MenuGroup[0].ShowGroup) HandleMain();//******* HERE IS WHERE IT OCCURS
if (MainGUI.MenuGroup[1].ShowGroup) HandleMultiplayerMenu();
if (MainGUI.MenuGroup[2].ShowGroup) HandleGameType();
if (MainGUI.MenuGroup[3].ShowGroup) HandlePlayerScreen();
if (MainGUI.MenuGroup[5].ShowGroup) HandlePlayerNameScreen();
if (MainGUI.MenuGroup[6].ShowGroup) HandleSinglePlayerScreen();
if (MainGUI.MenuGroup[4].ShowGroup) {//connecting to server message
if (NetConnected()){//go to player screen
MainGUI.MenuGroup[4].ShowGroup=false;
MainGUI.MenuGroup[3].ShowGroup=true;
MainGUI.MenuGroup[7].ShowGroup=true;
}
if (MainGUI.MenuItem[CancelJoinButton].State>0){
MainGUI.MenuItem[CancelJoinButton].State=0;
MainGUI.MenuGroup[4].ShowGroup=false;
MainGUI.MenuGroup[1].ShowGroup=true;
}
}
//if load game then StartNewGame=false; EnterGame=true;
if (dbEscapeKey ()==1){
if (MainGUI.MenuGroup[0].ShowGroup){
NetDisconnect();
return false;
}
else {
for (int i=1;i<MainGUI.MaxNumberOfGroups;i++) MainGUI.MenuGroup[i].ShowGroup=false;
MainGUI.MenuGroup[0].ShowGroup=true;
if (GameServer){
SendServerDownMessage();
ServerLeavingGame=true;
}
while (dbEscapeKey ()==1);
}
}
dbText(0,0,dbStr(tp1));
dbSync();
if ((ServerLeavingGame)&&(NetGetPlayerAmount()==0)) {
NetDisconnect();
ServerLeavingGame=false;
}
}
The fastest code is the code never written.