Archived

This topic is now archived and is closed to further replies.

debug assertion failed

This topic is 5149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i''m writing a level loader for a game that reads in a text file char by char. depending on what the char is, a certain block it put in the level(the level is a grid). Whenever i run the program, i get a ''debug assertion error'' it says somting like ''file!=NULL''. the blocks are models that are imported. block loader:
void smd::LoadSmd(char path[50]){
	FILE *file;
	char line[LINELENGTH];
	file=fopen(path,"rt");
	vertex v;
	bool inNode=false,inSkel=false,inTri=false;
	while (!feof(file)){
		fgets(line,LINELENGTH,file);
		if ((line[0]==''e'')&&(line[1]==''n'')&&(line[2]==''d'')){
			inNode=false;
			inSkel=false;
			inTri=false;
		}
		else if (inNode){
			//parse node line

		}
		else if (inSkel){
			//parse skeleton line

		}
		else if (inTri){
			//parse triangle line

			if (line[0]=='' ''){
				numOVerts++;
				sscanf(line,"  %d %f %f %f %f %f %f %f %f",
					&v.parent,
					&v.pos.x,&v.pos.y,&v.pos.z,
					&v.norm.x,&v.norm.y,&v.norm.z,
					&v.texCoord.x,&v.texCoord.y);
				verts.push_back(v);
			}
			else {
				sscanf(line,"%s",v.texPath);
			}
		}
		else {
			//probably at a comment, or a beginning or somthing

			if ((line[0]==''n'')&&(line[1]==''o'')){
				inNode=true;
			}
			else if ((line[0]==''s'')&&(line[1]==''k'')){
				inSkel=true;
			}
			else if ((line[0]==''t'')&&(line[1]==''r'')){
				inTri=true;
			}
			else {
				//forget it...

			}
		}
	}
	fclose(file);
}
level loader: note: blocks is a 3 dim array of Block blockMod,speedMod,finishMod,towerMod are preloaded models(smd)
void Level::loadLevel(char path[50]){
	//load the level file

	FILE *fi;
	char line[LINELENGTH];
	fi=fopen(path,"rt");
	fgets(line,LINELENGTH,fi);
	sscanf(line,"NAME %s",&name);//level name

	fgets(line,LINELENGTH,fi);
	sscanf(line,"GRAV %f",&grav);//level gravity

	fgets(line,LINELENGTH,fi);//balck line

	for (int h=0;h<3;h++){
		for (int r=0;r<200;r++){
			fgets(line,LINELENGTH,fi);//read next line

			for (int c=0;c<10;c++){
				switch(line[c]){//if char is a...

				case ''B'':blocks[h][c][r].setType(BLOCK,blockMod);//B then put a block in the grid

					break;
				case ''T'':blocks[h][c][r].setType(TOWER,towerMod);// T put a tower

					break;
				case ''S'':blocks[h][c][r].setType(SPEED,speedMod);// S put a speed block

					break;
				case ''F'':blocks[h][c][r].setType(FINISH,finishMod);//F put a finish block

					break;
				case ''.'':blocks[h][c][r].setType(EMPTY,NULL);//. put nothing

					break;
				default:MessageBox(NULL,"ERROR",NULL,NULL);// none of the above

					break;
				}
			}
		}
		fgets(line,LINELENGTH,fi);//3 blank lines

		fgets(line,LINELENGTH,fi);
		fgets(line,LINELENGTH,fi);
	}
	fclose(fi);
}
here is the setTpye function:
void Block::setType(type blkType,smd mod){
	blockType=blkType;
	model=mod;
}
i''ve found that if i comment out the blocks[h][c][r].setType(BLOCK,blockMod); in the level loading function, i don''t get the error/waring anymore. what is an assertion error and how would i fix this problem?

Share this post


Link to post
Share on other sites
Briefly, an assert (short for assertion) is a programming method used to short circuit your code when something goes wrong, in order to prevent other bad things from happening. You can find more through a google search.

The specific problem you're having results from internal error checking in the cstdio library. Having bound a file to a FILE* through fopen, whenever you try to read or write to that pointer, the I/O function you call asserts that the FILE* you pass is not null, or 0. This means that if the FILE* IS null, you will receive a warning like the one you did.

Most often a null file pointer to a read file indicates that the file did not exist at the time fopen was called. Ergo, fopen returned zero. Check to make sure the file is in the path where the executable is looking.

edit: After reviewing your code, it seems that you're passing the flag string "rt". I'm not familiar with 't' as a flag - might you have meant '+'?

[edited by - zealouselixir on November 9, 2003 6:14:20 PM]

Share this post


Link to post
Share on other sites