Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assertion failure CStringArray

Status
Not open for further replies.

john0532

Programmer
Jul 2, 2002
27
0
0
US
With a wizard I put a CStringArray within the application class "theApp". When I start the debugger I get the assertion failure before my code touches the CStringArray (as far as I know).

Here's the assertion failure:

Debug Assertion Failed!
Program:...\GapPlus.exe
File: afxcoll.inl
Line: 222
For information on...

The assertion is:
_AFXCOLL_INLINE CString CStringArray::GetAt(int nIndex) const
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
return m_pData[nIndex]; }

The watch pane gives me this info:
- theApp.m_siteArray {CStringArray}
+ CObject {CObject}
+ classCStringArray {&quot;CStringArray&quot;}
- m_pData 0x00000000 { ???}
m_pchData CXX0030: Error: expression cannot be evaluated
m_nSize 0
m_nMaxSize 0
m_nGrowBy 0

Here is the code I use after the assertion failure:

m_siteArray.SetSize(i, 250);
m_siteArray.SetAt(0, &quot; &quot;);

Here's the declaration in the .h file:
CStringArray m_siteArray;


Am I doing something obviously wrong
 
What is the code just before the assertion failure ?

K
 
As soon as it steps to the first line in InitInstance() (called by AfxWinMain()) I get the assertion failure.

BOOL CGapPlusApp::InitInstance()
{
TCHAR buf[512], LFbuf[512], DSNbuf[512], DBNamebuf[512], Userbuf[512];

Thanks for responding.
 
OK, so whats the value in i ?

Id guess that the line m_siteArray.SetSize(i, 250); is whats causing your assertion error.

(But having never used StringArray this is just conjecture at the moment !)

if you break the program before the assertion (but in that function), does the array have a valid address ?

Also, what is the size of the array there (before you make any calls on it)

I would assume that the array has a minimal size. Tell me what you see and I'll dig through some of our source code see if anyones used the array.

K
 
Here is a more complete set of the code which is about 400 lines of code below where it steps into InitInstance(). The value of i is 5.

i = rsShimShop.GetRecordCount() + 1;

m_siteArray.RemoveAll();
m_siteArray.SetSize(i, 250);
m_siteArray.SetAt(0, &quot; &quot;);
m_siteNameArray.RemoveAll();
m_siteNameArray.SetSize(i, 250);
m_siteNameArray.SetAt(0, &quot; &quot;);

i = 1;
while(!rsShimShop.IsEOF())
{
m_siteArray.SetAt(i, rsShimShop.m_ShimShopID);
m_siteNameArray.SetAt(i, rsShimShop.m_ShimShopLongName);
rsShimShop.MoveNext();
i++;
}
rsShimShop.Close();
 
OK< I'll take a look and see what I can find out. let you know later

K
 

If you're in debug mode right click on the toolbars and bring up the call stack. This will help you find what line is causing the assertion.

 
It's line 222 of afxcoll.inl:

_AFXCOLL_INLINE void CStringArray::SetAt(int nIndex, const CString& newElement)
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
m_pData[nIndex] = newElement; }

I put a break point in the calling function:
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)

I don't get the error until it hits the first line of code in InitInstance().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top