Click here to Skip to main content
15,923,789 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: dynamic allocation of arrays Pin
Sauce!30-Sep-08 2:16
Sauce!30-Sep-08 2:16 
GeneralRe: dynamic allocation of arrays Pin
Iain Clarke, Warrior Programmer30-Sep-08 3:21
Iain Clarke, Warrior Programmer30-Sep-08 3:21 
GeneralRe: dynamic allocation of arrays [modified] Pin
Sauce!30-Sep-08 5:01
Sauce!30-Sep-08 5:01 
GeneralRe: dynamic allocation of arrays Pin
Iain Clarke, Warrior Programmer30-Sep-08 5:31
Iain Clarke, Warrior Programmer30-Sep-08 5:31 
GeneralRe: dynamic allocation of arrays Pin
Sauce!30-Sep-08 5:43
Sauce!30-Sep-08 5:43 
GeneralRe: dynamic allocation of arrays Pin
Iain Clarke, Warrior Programmer30-Sep-08 6:02
Iain Clarke, Warrior Programmer30-Sep-08 6:02 
GeneralRe: dynamic allocation of arrays Pin
Sauce!2-Oct-08 5:05
Sauce!2-Oct-08 5:05 
GeneralRe: dynamic allocation of arrays [modified] Pin
Sauce!4-Oct-08 2:42
Sauce!4-Oct-08 2:42 
I've looked into the problem a bit further and the destructor for my Block object is being called from the following area of my UpdateWorld() function;

for(int i=0; i < 10; i++)<br />
{<br />
	Block theBlock;<br />
	p_CurrentBlock = &theBlock;<br />
	vector_BlockList.push_back(*p_CurrentBlock);<br />
}


Every time the for loop iterates, theBlock falls out of scope and thus it's destructor is called. I've yet to work out why that would be a problem (and I doubt it is) but it may be helpful information to know Smile | :)

EDIT: Wow, I'm very stupid indeed :P

When theBlock falls out of scope, p_CurrentBlock becomes a wild pointer. It could be pointing to anything! Blush | :O

Another edit: Problem solved! Thankyou very much for your help Iain Smile | :)

Btw you have a very cool name Cool | :cool:

Yet another edit™: I seem to have jumped the gun. Commenting out the following code fixed it, but when I made the necessary changes to it I still get the same problem! Frown | :(

for(int i=0; i < 10; i++)<br />
{<br />
Block theBlock;	<br />
vector_BlockList.push_back(theBlock);<br />
p_CurrentBlock = &vector_BlockList.back();<br />
}


Strangely, though THIS code, that is called elsewhere in my program, works fine.

if (p_CurrentBlock->isGrounded() == true)<br />
{<br />
Block theBlock;<br />
vector_BlockList.push_back(theBlock);<br />
p_CurrentBlock = &vector_BlockList.back();<br />
}


Commenting out the first code snippet makes it work, but commenting out the second one only doesn't, so it's not a matter of those two snippets conflicting with each other.

further edit:

if (p_CurrentBlock->isGrounded() == true)<br />
{<br />
Block theBlock;<br />
vector_BlockList.push_back(theBlock);<br />
p_CurrentBlock = &vector_BlockList.back();<br />
}


was always evaluating to false, and thus the statements were not executed. The culprit lies somewhere in

Block theBlock;<br />
vector_BlockList.push_back(theBlock);<br />
p_CurrentBlock = &vector_BlockList.back();


which most likely leads us back to the destructor for Tile Frown | :(

modified on Saturday, October 4, 2008 11:03 AM

GeneralRe: dynamic allocation of arrays Pin
Sauce!4-Oct-08 5:19
Sauce!4-Oct-08 5:19 
GeneralRe: dynamic allocation of arrays [modified] Pin
Sauce!4-Oct-08 5:34
Sauce!4-Oct-08 5:34 
GeneralRe: dynamic allocation of arrays [modified] Pin
Sauce!4-Oct-08 12:53
Sauce!4-Oct-08 12:53 
GeneralRe: dynamic allocation of arrays Pin
Sauce!17-Oct-08 20:58
Sauce!17-Oct-08 20:58 
Questionno WM_MOUSEHOVER in an edit Pin
followait28-Sep-08 18:58
followait28-Sep-08 18:58 
AnswerRe: no WM_MOUSEHOVER in an edit Pin
Iain Clarke, Warrior Programmer30-Sep-08 0:25
Iain Clarke, Warrior Programmer30-Sep-08 0:25 
QuestionCListCtrl Problem Pin
Dhiraj kumar Saini28-Sep-08 18:53
Dhiraj kumar Saini28-Sep-08 18:53 
AnswerRe: CListCtrl Problem Pin
_AnsHUMAN_ 28-Sep-08 18:59
_AnsHUMAN_ 28-Sep-08 18:59 
AnswerRe: CListCtrl Problem Pin
Naveen28-Sep-08 19:01
Naveen28-Sep-08 19:01 
QuestionWrite a buffer to stringstream Pin
CodingLover28-Sep-08 18:43
CodingLover28-Sep-08 18:43 
AnswerRe: Write a buffer to stringstream Pin
Naveen28-Sep-08 19:04
Naveen28-Sep-08 19:04 
GeneralRe: Write a buffer to stringstream Pin
CodingLover28-Sep-08 19:08
CodingLover28-Sep-08 19:08 
GeneralRe: Write a buffer to stringstream Pin
Naveen28-Sep-08 19:26
Naveen28-Sep-08 19:26 
NewsRe: Write a buffer to stringstream Pin
CodingLover28-Sep-08 19:35
CodingLover28-Sep-08 19:35 
GeneralRe: Write a buffer to stringstream Pin
Naveen28-Sep-08 19:54
Naveen28-Sep-08 19:54 
GeneralRe: Write a buffer to stringstream Pin
CodingLover28-Sep-08 20:18
CodingLover28-Sep-08 20:18 
GeneralRe: Write a buffer to stringstream Pin
Naveen28-Sep-08 20:29
Naveen28-Sep-08 20:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.