Need some help with ImageList and crash in Release

it stops hereHello,
my code works fine in Debug but not in Release. It will crash at wincore.cpp
It will compile in both with no error, but will crash in Release.
Can you help me....500 points with a solution.
Please help.
Thank you.
Best regards,
Thomas
 //---------------------------- ImageList ------------------------------
	m_Image.Create(3,3,ILC_COLOR16,1,1);  //1. 3=Breite  2. 3=Höhe
	CBitmap myBitmap;

	myBitmap.LoadBitmap(IDB_BITMAP_WAAGE_KLEIN);
    m_Image.Add(&myBitmap,RGB(0,0,0));
	myBitmap.DeleteObject();
 
 
	//set the CImageList
	pHeader->SetImageList(&m_Image);
	//wichtig columns nicht mehr zum verschieben
	m_List1.GetHeaderCtrl()->EnableWindow(FALSE);

	//set the ImageList
	HDITEM hdi;
	hdi.mask=HDI_IMAGE|HDI_FORMAT;
	for(int i=1; i<8;i=i+1)
	{
		if(pHeader->GetItem(i,&hdi));
		{
			hdi.mask=HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
			hdi.fmt=HDF_CENTER|HDF_IMAGE|HDF_STRING;
			if(i==0)
			{
				hdi.pszText="WaageNr";
				hdi.cxy=55;
			}
			if(i==1)
			{
				hdi.pszText="ABNr";
				hdi.cxy=55;
			}
			if(i==2)
			{
				hdi.pszText="WiegeNr";
				hdi.cxy=65;
			}
			if(i==3)
			{
				hdi.pszText="Netto";
				hdi.cxy=50;
				hdi.fmt=HDF_RIGHT|HDF_IMAGE|HDF_STRING;
			}
			if(i==4)
			{
				hdi.pszText="Brutto";
				hdi.cxy=52;
				hdi.fmt=HDF_RIGHT|HDF_IMAGE|HDF_STRING;
			}
			if(i==5)
			{
				hdi.pszText="Stck";
				hdi.cxy=47;
				hdi.fmt=HDF_RIGHT|HDF_IMAGE|HDF_STRING;
			}
			if(i==6)
			{
				hdi.pszText="Datum";
				hdi.cxy=78;
			}
			if(i==7)
			{
				hdi.pszText="Mitarbeiter";
				hdi.cxy=82;
				hdi.fmt=HDF_LEFT|HDF_IMAGE|HDF_STRING;
			}
	 
			hdi.iImage=i;
			pHeader->SetItem(i,&hdi);
		}
	}

Open in new window

Thomas StockbrueggerAsked:
Who is Participating?
 
ZoppoConnect With a Mentor Commented:
Hm - strange, what kind of errors do you see?

One thing I found in the code could maybe cause the problem - here you instantiate an uninitialized HDITEM:

   123: HDITEM hdi;

In DEBUG usually those structs are automatically filled with zero-bytes, in RELEASE they aren't, so you should do it yourself, i.e. simply like this:

   HDITEM hdi;
   ZeroMemory( &hdi, sizeof( hdi ) );


to avoid any uninitilized data is used.

If this doesn't solve the problem IMO you should try to get the mentioned ReleaseWithSymbols running.
0
 
ZoppoCommented:
Hi tsp2002,

first how do you now the crash is related to the image-list stuff? From info you posted here there's no indication for this.

To find crashs in RELEASE builds my first suggestion is to create a new configuration like i.e. 'Win32 ReleaseWithSymbols' as copy from 'Win32 Release' but options set to generate debug info. To do so open the configuration manager (Build->Configuration Manager), select the project and choose <New> in the Configuration column's combo box. In the upcoming dialog enter the new configuration name (i.e. ReleaseWithSymbols) and select the Release configuration in the Copy settings from combo box.

Then open the project's properties and change the following options in the new configuration:
- C/C++\General\Debug Information Format: Program Database
- C/C++\Optimization\Optimization: Disabled
- Linker\Debugging\Generate Debug Info: Yes

When you build this new configuration it most probably should crash too for the same cause, but now you should be able to see more info about why/where it crashs.

Hope that helps,

ZOPPO
0
 
Thomas StockbrueggerAuthor Commented:
did you mean that?Hello Zoppo,
thanks for your fast answer. When I do this I will get a lot of errors...but no one in my current file...where the crash is.
I know that it comes from the image list, because when I remove the code...it runs fine.

//###########################################################################################
BOOL CWaageDialog::OnInitDialog()
{
	CDialog::OnInitDialog();
    
         //==================================
	 WaagenTextDatei_lesen();<------------ here is the code
	//==================================
	 
		
	//-------------------- Titel vom Dialogbox ändern ----------------------------------------------
	SetWindowText("Waage");
	//----------------------------------------------------------------------------------------------
     //Auftrag suchen 
	 m_bitmap_suchen.LoadBitmap(IDB_BITMAP2);
	 m_button_Auftrag_suchen.SetBitmap(m_bitmap_suchen); 

    //Exit Button 
	 m_bitmap_exit.LoadBitmap(IDB_BITMAP_EXIT);
	 m_button_Exit.SetBitmap(m_bitmap_exit);  
.
.
.
.



void CWaageDialog::WaagenTextDatei_lesen(void)
{	 

//--------------------- Listenelement klein neue Waagendaten ---------------------------
  
	//m_List1.SetFont(fontPtr);//kleine Schrift

 //Textfarbe blau
 m_List1.SetTextColor(RGB(0,0,255));
 //Texthintergrundfarbe 
 m_List1.SetTextBkColor(RGB(255,255,255));
 //Listenelement Hintergrundfarbe
 m_List1.SetBkColor(RGB(255,255,255));
 //Listenelement Gitterlinien
 //m_List1.SetExtendedStyle(LVS_EX_GRIDLINES);//|LVS_SINGLESEL|LVS_EX_CHECKBOXES); 
m_List1.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);   //Listenelement Gitterlinien

 //--------------- Erstelle neue Schrift ------------
	 CString strSchriftart1="Microsoft Sans Serif";
  
	
	 CFont *fontPtr = new CFont();
	 fontPtr->CreateFont(
	 12,
	  0,
	  0,
	  0,
	 FW_NORMAL,
	  0,
	  0,
	  0,
	 DEFAULT_CHARSET,
	 OUT_CHARACTER_PRECIS,
	 CLIP_CHARACTER_PRECIS,
	 DEFAULT_QUALITY,
	 DEFAULT_PITCH|FF_DONTCARE,
	 strSchriftart1);
	
	//-------------------------------------------------- Original Listenelement
    CHeaderCtrl *pHeader = m_List1.GetHeaderCtrl();
    ASSERT(pHeader);
    pHeader->SetFont(fontPtr);


 //........................................................
	m_List1.InsertColumn(0,"Nr",LVCFMT_CENTER,35);//WaageNr
    m_List1.InsertColumn(1,"ABNr*",LVCFMT_CENTER,55);
    m_List1.InsertColumn(2,"WiegeNr*",LVCFMT_CENTER,50);
	m_List1.InsertColumn(3,"Netto*",LVCFMT_CENTER,60);
    m_List1.InsertColumn(4,"Brutto*",LVCFMT_CENTER,60);
	m_List1.InsertColumn(5,"Stck*",LVCFMT_CENTER,60);
    m_List1.InsertColumn(6,"Datum*",LVCFMT_CENTER,65);
    m_List1.InsertColumn(7,"Mitarbeiter*",LVCFMT_LEFT,60);
    m_List1.InsertColumn(8,"Abmessung",LVCFMT_CENTER,60);
	m_List1.InsertColumn(9,"Stckgew.",LVCFMT_RIGHT,60);
	m_List1.InsertColumn(10,"theor.Gew.",LVCFMT_RIGHT,60);
	m_List1.InsertColumn(11,"theor.Stck",LVCFMT_RIGHT,60);
	m_List1.InsertColumn(12,"Abweichung",LVCFMT_CENTER,60);

	m_List1.SetColumnWidth(0,35);
	m_List1.SetColumnWidth(1,55);
	m_List1.SetColumnWidth(2,55);
	m_List1.SetColumnWidth(3,50);
	m_List1.SetColumnWidth(4,50);
	m_List1.SetColumnWidth(5,45);
	m_List1.SetColumnWidth(6,78);
	m_List1.SetColumnWidth(7,79);
	m_List1.SetColumnWidth(8,160);
	m_List1.SetColumnWidth(9,60);
	m_List1.SetColumnWidth(10,60);
	m_List1.SetColumnWidth(11,60);
	m_List1.SetColumnWidth(12,115);
	
 



 //---------------------------- ImageList ------------------------------
	m_Image.Create(3,3,ILC_COLOR16,1,1);  //1. 3=Breite  2. 3=Höhe
	CBitmap myBitmap;

	myBitmap.LoadBitmap(IDB_BITMAP_WAAGE_KLEIN);
    m_Image.Add(&myBitmap,RGB(0,0,0));
	myBitmap.DeleteObject();
 
 	//set the CImageList
	pHeader->SetImageList(&m_Image);
	//wichtig columns nicht mehr zum verschieben
	m_List1.GetHeaderCtrl()->EnableWindow(FALSE);



	
 
	//set the ImageList
	HDITEM hdi;
	hdi.mask=HDI_IMAGE|HDI_FORMAT;
	for(int i=1; i<8;i=i+1)
	{
		if(pHeader->GetItem(i,&hdi));
		{
			hdi.mask=HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
			hdi.fmt=HDF_CENTER|HDF_IMAGE|HDF_STRING;
			if(i==0)
			{
				hdi.pszText="WaageNr";
				hdi.cxy=55;
			}
			if(i==1)
			{
				hdi.pszText="ABNr";
				hdi.cxy=55;
			}
			if(i==2)
			{
				hdi.pszText="WiegeNr";
				hdi.cxy=65;
			}
			if(i==3)
			{
				hdi.pszText="Netto";
				hdi.cxy=50;
				hdi.fmt=HDF_RIGHT|HDF_IMAGE|HDF_STRING;
			}
			if(i==4)
			{
				hdi.pszText="Brutto";
				hdi.cxy=52;
				hdi.fmt=HDF_RIGHT|HDF_IMAGE|HDF_STRING;
			}
			if(i==5)
			{
				hdi.pszText="Stck";
				hdi.cxy=47;
				hdi.fmt=HDF_RIGHT|HDF_IMAGE|HDF_STRING;
			}
			if(i==6)
			{
				hdi.pszText="Datum";
				hdi.cxy=78;
			}
			if(i==7)
			{
				hdi.pszText="Mitarbeiter";
				hdi.cxy=82;
				hdi.fmt=HDF_LEFT|HDF_IMAGE|HDF_STRING;
			}
	 
			hdi.iImage=i;
			pHeader->SetItem(i,&hdi);
		}
	}
	 

Open in new window

0
 
Thomas StockbrueggerAuthor Commented:
Hi Zoppo,
you are great....that was the error:
   HDITEM hdi;
   ZeroMemory( &hdi, sizeof( hdi ) );<--------------- without this it will crash on release

Thank you very much.
It is somtimes strange...I thought it would crash first at debug modus...but you never know.
Vielen Dank und schönen Feierabend....Beste Grüße von Thomas



P.S. still learning MFC
0
 
ZoppoCommented:
Greate - I'm glad I could help.

The cause is as told above simply the values weren't initialized so the members of hdi are initially set to any random numbers. Depending on these random numbers using this struct might or might not cause problems ...

And BTW, that's not really MFC related, it's a plain C/C++ problem.

Best regards,

ZOPPO

PS: Auch 'nen schönen Feierabend, Danke ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.