-
March 17th, 2004, 03:02 PM
#1
CArray asserts at program end
Hi!
I have an assertion when my application ends. I can track it to when the clean up is being done on my CArray. I fill the array using the SetAtGrow() function...Setting at each enumeration.
m_aryVals.SetSize(nSysConfigDefault);
typeValues temp;
temp.strText = "Channel";
temp.nType = nSysConfigTitle;
temp.nCol = 0;
temp.nRow = 0;
temp.lColor = ColorBlack;
temp.bBold = TRUE;
temp.nWidth = 55;
m_aryVals.SetAtGrow(nChannelTitle, tempSysConfig);
Where nChannelTitle is an enumerated type from...
enum ESYSCONFIGDISPCELL
{
nChannelTitle,
nInControlTitle,
nChStatusTitle,
nASVersionTitle,
nOSVersionTitle,
nAIPVersionTitle,
nCPUChSumTitle,
nAIPChSumTitle,
nNVMChSumTitle,
nSysConfigDefault
};
The CArray is declared as...
CArray<typeValues,typeValues> m_aryValues;
...where typeValues is as
typedef struct tagValues
{
CString strText;
unsigned long lColor;
BOOL bBold;
int nRow;
int nCol;
int nWidth;
ESYSCONFIGTYPES nType;
}typeValues;
and ESYSCONFIGTYPES is as
enum ESYSCONFIGTYPES
{
nText,
nSysConfigTitle,
nGreenLight,
nGrayLight
};
...It asserts at the code in AFXTEMPL.h at the line
ASSERT(m_nSize <= m_nMaxSize);
and...
m_nSize = 27 and m_nMaxSize = 27
Here's the function where it asserts...
template<class TYPE, class ARG_TYPE>
void CArray<TYPE, ARG_TYPE>::AssertValid() const
{
CObject::AssertValid();
if (m_pData == NULL)
{
ASSERT(m_nSize == 0);
ASSERT(m_nMaxSize == 0);
}
else
{
ASSERT(m_nSize >= 0);
ASSERT(m_nMaxSize >= 0);
ASSERT(m_nSize <= m_nMaxSize);
ASSERT(AfxIsValidAddress(m_pData, m_nMaxSize * sizeof(TYPE)));
}
}
Thanks in advance!
We must become the change we wish to see in our world. ~ Gandhi
-
March 18th, 2004, 12:10 AM
#2
You have set the size of the array...
m_aryVals.SetSize(nSysConfigDefault);
Then you add a new element (I suppose that is it - your code doesn't show the declaration of "tempSysConfig")
m_aryVals.SetAtGrow(nChannelTitle, tempSysConfig);
at index 0, the enumerated value of nChannelTitle. If all the elements are set at index 0, you will have only 1 element populated in your array, but room for nSysConfigDefault elements. That may be your problem right there. When you call DestructElements(), there may not be enough objects to destroy. It's just a guess - you don't have enough code shown.
If you are going to set the size before hand, then use SetAt(). As a general rule of thumb, if you set the size statically, you should set the elements right after setting the size so that it is clear that the array is populated correctly.
Steve
-
March 18th, 2004, 11:10 AM
#3
got it!
I figured it out...but thanks.
We must become the change we wish to see in our world. ~ Gandhi
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|