Debug Assertion Failed! What??

I keep getting this error message and I have no idea what it means or why I'm getting it. I'm doing the DVD catalog that pulls its data from a text file. I can get it to calculate how many dvds are represented by the data in the text file. Then I use that number to dynamically allocate an array of DVD objects. I can get it to populate each DVD object in the array with the data in the text file, however before it finishes I get this error message.

" Debug Assertion Failed!
Program: ....cuments\Visual Studio\
blah blah\ more pathway\...\dbgdel.cpp
Line 52

Expression;_BLOCK_TYPE_IS_VALID(pHEAD->nBlockUse)"

I found some info on assertions at:
http://msdn.microsoft.com/en-us/library/ew16s3zc%28VS.71%29.aspx

but I don't understand it. I think I'm a bit out of my league on this.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 // DVDMain.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "DVD.h"


int countDVD (fstream &);


int main()
{
	string line;
	int numDVD,i;
	fstream dvdFile;
	DVD *ptrDVDarray;

	dvdFile.open("c:\\users\\public\\dvd.txt", ios::in|ios::binary);
	
	numDVD = countDVD(dvdFile);
	
	cout<<numDVD<<endl;

	ptrDVDarray = new DVD[numDVD];
	
	dvdFile.clear();
	dvdFile.seekg(0L, ios::beg);
	
	for (i=0; i < numDVD; i++)	
	{
		getline(dvdFile, line, '\n');
		(ptrDVDarray + i)->setTitle(line); 
		
		getline(dvdFile, line, '\n');
		(ptrDVDarray + i)->setTime(line); 
	
		getline(dvdFile, line, '\n');
		(ptrDVDarray + i)->setYear(line);
	
		getline(dvdFile, line, '\n');
		(ptrDVDarray + i)->setActors(line);
	}
	
	for (i=0; i < numDVD; i++)
	{
	cout<< (ptrDVDarray + i)->getTitle() <<endl;
	cout<< (ptrDVDarray + i)->getTime() <<endl;
	cout<< (ptrDVDarray + i)->getYear() <<endl;;
	cout<< (ptrDVDarray + i)->getActors() <<endl;
	}

	delete ptrDVDarray;
	return 0;
}
//*****Functions*********


int countDVD(fstream &infile)
{ 
	int numDVD = 0; //hold the number of dvds
	int newline = 0;  //hold the number of '\n'
	char nL; 
	
	//set read position at begining of file
	infile.seekg(0L, ios::beg);
	
	//set pos to value of current position
	long pos = infile.tellg();
		
	//Loop to read each character and 
	// search for '\n' till eof
	while(!infile.eof())
	{    
		//set read point to current position
		infile.seekg(pos, ios::beg);
		// get/copy character at curent position 
		 nL = infile.get();
		
		//test for '\n' and increment the '\n' counter (newline)
		if (nL == '\n')
		{
			newline++;
			//increment numDVD everytime newline hit 5
			if(newline == 5)
			{
			numDVD++;
			newline = 0; 
			}
		}
		// move to the next read position
		pos++;
	}//end while
	return numDVD;
}
Last edited on
One thing that stands out is you should be using delete[] to delete your array. Does that fix the problem?

You may also want to step up the call stack from when the assertion failed and see where in your code the problem originated.
That did it! All that just from a couple of missing brackets. Love it!! It all about the details. Thanks! I hate it when I miss something so simple.

I'm not sure how to "step up the call stack" but I will check out the MVS website and see if I can figure it out. Thanks again!
Topic archived. No new replies allowed.