Click here to Skip to main content
15,899,474 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Corruption of the heap. Why ? Pin
Erudite_Eric8-Jun-12 2:35
Erudite_Eric8-Jun-12 2:35 
GeneralRe: Corruption of the heap. Why ? Pin
sdancer758-Jun-12 6:02
sdancer758-Jun-12 6:02 
AnswerRe: Corruption of the heap. Why ? Pin
Aescleal8-Jun-12 3:00
Aescleal8-Jun-12 3:00 
GeneralRe: Corruption of the heap. Why ? Pin
sdancer758-Jun-12 6:03
sdancer758-Jun-12 6:03 
GeneralRe: Corruption of the heap. Why ? Pin
sdancer759-Jun-12 3:43
sdancer759-Jun-12 3:43 
GeneralRe: Corruption of the heap. Why ? Pin
Aescleal9-Jun-12 9:51
Aescleal9-Jun-12 9:51 
GeneralRe: Corruption of the heap. Why ? Pin
sdancer759-Jun-12 23:58
sdancer759-Jun-12 23:58 
GeneralRe: Corruption of the heap. Why ? Pin
sdancer7512-Jun-12 3:18
sdancer7512-Jun-12 3:18 
Ok, I found the cause of the problem.

The default for views is to allocate them on the heap and the default post-cleanup is to 'delete this'.

So, in my situation I created the window in the stack, like it shows below.
C++
VERIFY(Create(_T("MyWind"), NULL, WS_CHILD | WS_VISIBLE, CXTPEmptyRect(), pParentWnd,  IDD_TABSHEET2, &context));


The default behavior of the CView cleanup is to delete this. Indeed, if you check inside the viewcore.cpp you will see, something like this :
C++
// self destruction
void CView::PostNcDestroy()
{
	// default for views is to allocate them on the heap
	//  the default post-cleanup is to 'delete this'.
	//  never explicitly call 'delete' on a view
	delete this;
}


That thing is all screwed up in my case. The solution ? Just override the CCatalogView::PostNcDestroy and comment the CFormView::PostNcDestroy(); to prevent calling the CView::PostNcDestroy.
C++
void CCatalogView::PostNcDestroy()
{
	// TODO: Add your specialized code here and/or call the base class
	_ASSERTE( _CrtCheckMemory( ) );

	//Don't call default PostNCDestroy which it calls CView:: delete this
	//because you get a heap corruption since the view is created on the stack.
	//CFormView::PostNcDestroy();


}

Hope, it helps someone.

Regards,
sdancer75

QuestionException when debugging Multithread Pin
ForNow7-Jun-12 19:04
ForNow7-Jun-12 19:04 
AnswerRe: Exception when debugging Multithread Pin
«_Superman_»7-Jun-12 19:15
professional«_Superman_»7-Jun-12 19:15 
GeneralRe: Exception when debugging Multithread Pin
ForNow7-Jun-12 23:53
ForNow7-Jun-12 23:53 
GeneralRe: Exception when debugging Multithread Pin
ForNow7-Jun-12 23:58
ForNow7-Jun-12 23:58 
AnswerRe: Exception when debugging Multithread Pin
Erudite_Eric7-Jun-12 20:34
Erudite_Eric7-Jun-12 20:34 
AnswerRe: Exception when debugging Multithread Pin
Richard MacCutchan7-Jun-12 21:53
mveRichard MacCutchan7-Jun-12 21:53 
GeneralRe: Exception when debugging Multithread Pin
Erudite_Eric7-Jun-12 23:35
Erudite_Eric7-Jun-12 23:35 
GeneralRe: Exception when debugging Multithread Pin
Richard MacCutchan8-Jun-12 0:19
mveRichard MacCutchan8-Jun-12 0:19 
QuestionCalculate checksum using ASLR Pin
Giggsey737-Jun-12 8:39
Giggsey737-Jun-12 8:39 
QuestionRe: Calculate checksum using ASLR Pin
David Crow7-Jun-12 8:43
David Crow7-Jun-12 8:43 
AnswerRe: Calculate checksum using ASLR Pin
Giggsey737-Jun-12 8:46
Giggsey737-Jun-12 8:46 
AnswerRe: Calculate checksum using ASLR Pin
David Crow7-Jun-12 8:55
David Crow7-Jun-12 8:55 
GeneralRe: Calculate checksum using ASLR Pin
Giggsey737-Jun-12 9:08
Giggsey737-Jun-12 9:08 
GeneralRe: Calculate checksum using ASLR Pin
Giggsey738-Jun-12 8:34
Giggsey738-Jun-12 8:34 
GeneralRe: Calculate checksum using ASLR Pin
Randor 8-Jun-12 9:48
professional Randor 8-Jun-12 9:48 
GeneralRe: Calculate checksum using ASLR Pin
Giggsey738-Jun-12 18:48
Giggsey738-Jun-12 18:48 
GeneralRe: Calculate checksum using ASLR Pin
Randor 9-Jun-12 4:36
professional Randor 9-Jun-12 4:36 

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.