step by step debug != run debug

This is a discussion on step by step debug != run debug within the Windows Programming forums, part of the Platform Specific Boards category; This is driving me insane. I step thru my program and it works flawlessly every time. I click the ! ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    170

    Exclamation step by step debug != run debug

    This is driving me insane. I step thru my program and it works flawlessly every time. I click the ! to run it and it behaves differently.

    Has anyone seen this before? It is still the debug version in both cases. It's just whether I step thru or not that makes the difference. I did a rebuild all but that has no effect.

    Ideas?
    Best Regards,

    Bonkey

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    What is the exact problem that occurs when you arent running the debugger?
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    I am debugging the problem of corruption in my earlier post.

    What I found was that it works in every circumstance when I debug. I found a very simple case to test and run it step by step and then not step by step.

    It goes like this. I am reading 2 CStringList objects from a file. I make a modification to the string list then save it.

    When I step thru its perfect. Each String reads in correctly. I can make modifications, exit it watch them saved to the file.

    When I run it (using !) it will read the data from the file but when it writes, it basically doesnt write the second CStringList.

    I step by step make some mods. Run with ! and the mods are there 1 time and lost the next time.

    I can run in step by step 20 times and the data is never lost.

    Is this the info you needed?
    Best Regards,

    Bonkey

  4. #4
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Post your source code and let us have a look at it.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    here it is:

    OnInitDialog is where I read the CStringList from the file.
    AddPlayer is where I read the CStringList
    RemovePlayer is where I write the CStringList
    OnRemoteClose is where I write the CStringLists to the file

    Code:
    BOOL CPlayersDialog::OnInitDialog() 
    {
    	CDialog::OnInitDialog();
    
    	// TODO: Add extra initialization here
    
    	UpdateData(TRUE);  // Read what is typed in.
    
    
    	if(PlayerFile.Open("C:\\playerinfo.dat",CFile::modeNoTruncate|CFile::modeReadWrite|CFile::shareExclusive,NULL))
    	{
    	CArchive ar(&PlayerFile, CArchive::load); // Load its contents into a CArchive
    	
    	m_Players.Serialize(ar);
    	m_Text.Serialize(ar);
    	PlayerFile.Close();
    	}
    
    
    	return TRUE;  // return TRUE unless you set the focus to a control
    	              // EXCEPTION: OCX Property Pages should return FALSE
    }
    
    void CPlayersDialog::AddPlayer(CString Player)
    {
    	int i,j;
    	POSITION pos;
    	BOOL found=false;
    	
    	for(i=0;i<10;i++)
    	{
    		if(PLAYERS[i][0] == "")
    		{
    			PLAYERS[i][0]=Player;
    
    			for(j=0;j<m_Players.GetCount();j++)
    			{
    				pos=m_Players.FindIndex(j);
    				if( m_Players.GetAt(pos) == Player)
    				{
    					pos=m_Text.FindIndex(j);
    					TEXTLINE[i][0]=m_Text.GetAt(pos);
    					found=true;
    					break;
    				}
    			}
    
    			if(!found)
    			{
    				m_Players.AddTail(Player);
    				m_Text.AddTail("New Player");
    				TEXTLINE[i][0]=("New Player");
    			}
    
    			break;
    		}
    	}
    
    	UpdateData(FALSE);
    }
    
    void CPlayersDialog::RemovePlayer(CString Player)
    {
    	int i,j;
    	CString Name,*Text;
    	POSITION pos;
    	BOOL found=false;
    
    	UpdateData(true);
    
    	for(i=0;i<10;i++)
    		if(PLAYERS[i][0] == Player)
    		{
    			Name=PLAYERS[i][0];
    			Text= new CString(TEXTLINE[i][0]);
    			break;
    		}
    
    			for(j=0;j<m_Players.GetCount();j++)
    			{
    				pos=m_Players.FindIndex(j);
    				if( m_Players.GetAt(pos) == Name)
    				{
    					pos=m_Text.FindIndex(j);
    					m_Text.SetAt(pos,Text[0]);
    					found=true;
    					break;
    				}
    			}
    
    			if(!found)
    			{
    				m_Players.AddTail(Player);
    				m_Text.AddTail("New Player");
    			}
    
    	UpdateData(false);
    	delete(Text);
    
    }
    
    void CPlayersDialog::OnRemoteClose()
    {
    	int i;
    	CFileException e;
    
    	UpdateData(true);
    
    	((CPokerpalDlg *)m_parent)->m_flag=false;
    	for(i=0;i<10;i++)
    	{
    		if(PLAYERS[i][0] != "")
    			RemovePlayer(PLAYERS[i][0]);
    	}
    
    	if( !PlayerFile.Open("C:\\playerinfo.dat",CFile::modeCreate|CFile::modeReadWrite|CFile::shareExclusive,&e))
    	   afxDump << "File could not be opened " << e.m_cause << "\n";
    
    
    	CArchive ar (&PlayerFile, CArchive::store); // Load its contents into a CArchive
    	m_Players.Serialize(ar);
    	m_Text.Serialize(ar);
    
    	OnOK();
    }
    Best Regards,

    Bonkey

  6. #6
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    I won't say that I figured it out, but I have gotten it to work.

    It had to do with the writing of the file. Sometimes it would just fail. I added a messagebox to popup when it failed so I could test it.

    I ended up adding a binary flag to the Open options in both cases. I also moved the CFile definition into the 2 functions, reducing its scope and allowing the destructor to be called in between the accesses. I changed the flag on the write from readwrite to write.

    I removed the PlayerFile.Close() as this was causing strange problems.

    I don't know why these things solved the problem. I am still interested in opinions, but if your sorting thru the code, I just want to let you know that it is working now.
    Best Regards,

    Bonkey

  7. #7
    Registered User
    Join Date
    Aug 2002
    Posts
    170

    Thumbs up

    1 last thing:

    ar.Close(); //The archive must be closed after it is finished writing to the file. Or your PlayerFile.Close() will fail.
    Best Regards,

    Bonkey

  8. #8
    Visionary Philosopher Sayeh's Avatar
    Join Date
    Aug 2002
    Posts
    212
    You didn't solve the problem-- you just changed the RAM environment so you're not running into it (but it's still there).

    This kind of problem is because something is corrupting in RAM. When the program runs at full speed, RAM is changing faster and differently than it is while running under the debugger. As such, you're not seeing what's truly happening under the debugger.

    Does it crash under fullspeed under the debugger? Hopefully it will. If so, just start putting in a break point and make it run full speed until it hits it. If it doesn't crash before it hits the breakpoint, then move the breakpoint a little further down and try again. Tedious, yes. But worth it.

    You can also use a '#define' and '#ifdef' combination to define out portions of code. If you remove a section of code and the problem codes away, you know it's in that code.

    I would really recommend you check your allocations, and deallocations, and overruns.
    It is not the spoon that bends, it is you who bends around the spoon.

  9. #9
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    Thanks for the suggetion. It was erroring when I ran it full speed with the debugger. The problem ended up being caused by my file access methods. I kept thinking I had it all resolved. Then I would tun my binary on win2000 box and I would get file access errors.

    I finally got it all straigtened out. The answer was that there is a Close function for the CArchive. I was not aware of this. Adding ar.Close() fixed everything.

    Thanks for all the help.

    --Bonkey
    Best Regards,

    Bonkey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. makefiles - debug & release?
    By cpjust in forum C Programming
    Replies: 6
    Last Post: 10-26-2007, 05:00 PM
  2. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 12:08 PM
  3. Compiled App as release - won't run - as debug runs
    By XenoCodex Admin in forum C++ Programming
    Replies: 7
    Last Post: 08-05-2002, 05:43 PM
  4. this sites Compiler Resources Specs.
    By Powerfull Army in forum C++ Programming
    Replies: 9
    Last Post: 07-08-2002, 07:12 PM
  5. Ask about Debug Assert Failed
    By ooosawaddee3 in forum C++ Programming
    Replies: 0
    Last Post: 04-25-2002, 12:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21