|
-
October 5th, 1999, 03:39 AM
#1
Access Violation w/ "new"
I get an access violation when running the Debug version of the following code (MFC VC++ 4.0). The Release version runs through with no apparent problems. Help as to how to write it properly and avoid the Access Violation (which occurs in processing the last line). Please email all help to [email protected].
The Code:
struct S_LeagueDirType *p_LeagueList;
unsigned int length = m_MaxLeagueCoord + 1;
delete [] p_LeagueList;
p_LeagueList = new struct S_LeagueDirType [length];
-
October 5th, 1999, 03:47 AM
#2
Re: Access Violation w/ "new"
It may cause an access violation if you trying to delete without assigning first. Try to change this code to:
struct S_LeagueDirType *p_LeagueList = NULL;
unsigned int length = m_MaxLeagueCoord + 1;
if (p_LeagueList)
delete [] p_LeagueList;
p_LeagueList = new struct S_LeagueDirType [length];
Hope, it helps.
Jack.
-
October 5th, 1999, 04:01 AM
#3
Re: Access Violation w/ "new"
Hi,
The problem is that p_LeagueList is initialized by "random" number and delete[] p_LeagueList tries to delete array of S_LeagueDirType at that "random" address.
Try this:
struct S_LeagueDirType *p_LeagueList=0;
unsigned int length = m_MaxLeagueCoord + 1;
delete [] p_LeagueList;// btw this line does nothing
p_LeagueList = new struct S_LeagueDirType [length];
Good luck,
Oleg.
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
|