GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Nov-2007, 23:47
Algar Algar is offline
Junior Member
 
Join Date: Sep 2007
Posts: 92
Algar will become famous soon enough

Pointer going wild and magically back to normal again (sort of)


2 code snippets, issue stated below.

CPP / C++ / C Code:
GameDlg::GameDlg(MapCtrl* map, Character* fighter, CWnd* pParent)
	: CDialog(GameDlg::IDD, pParent)
{
    // BREAK #1	

	//Log Window
	pLog = new LogDlg();

    // BREAK #2

	pLog->Create(LogDlg::IDD);
	pLog->ShowWindow(SW_SHOW);
	
	//Create the GameEngine
	pGame = new GameEngine(map, fighter, pLog);
//......
later in the same file.... (and later in code execution)
CPP / C++ / C Code:
void GameDlg::OnPaint()
{
	CPaintDC dc(this);
	pMap->paint(&dc);   // BREAK #3
}

Ok, so I am watching map in constructor up top.
When I run debug, I get the following:

Break #1:
Map is ok, all values normal

Break #2
Map is total garbage values, all bad pointers, unknown stuff, a bunch of question marks etc...

Break #3
Still garbage like #2.

Break #3 again (this gets called twice at the start)
All the values are ok again.

Normal I might not care since it eventually returns to normal, however after break #1 I need to pass that pointer to another window as shown in the code, and when that window is created it is seeing those garbage values.

This behavior seems totaly wild to me, anyone care to make a guess, or know of a good way to hunt this down ?

I tried "stepping" in but I edned up going through about 10 library files where I had no clue what was going on.

The only line of code between the watch telling me map is good and then telling me map is bad, is this: pLog = new LogDlg();

But this class has absolutely nothing to do with the map data / classes / whatever. No relation of any kind
  #2  
Old 09-Nov-2007, 07:33
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Pointer going wild and magically back to normal again (sort of)


Is it possible that map has not been allocated yet? Maybe before you called pLog = new Log(), map was reading values that were left over from the last time you ran the program and when you create the new log, it overwrites that memory location.

That might be something to look at. I don't know. Maybe the code where map gets allocated.
  #3  
Old 09-Nov-2007, 12:25
Algar Algar is offline
Junior Member
 
Join Date: Sep 2007
Posts: 92
Algar will become famous soon enough

Re: Pointer going wild and magically back to normal again (sort of)


Sorry, I guess it was working good afterall. I found a bug in another function and now its all working fine.

Its weird how the "watch", and the "locals" in VS2005 were giving me such weird results though, maybe I just don't understand the VS debugging system well enough. Anyway, thanks fakepoo
 

Recent GIDBlogPrepping for deployment by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:30.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.