Getting Frustrated

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Paddon
Posts: 43
Joined: Thu Jul 06, 2006 4:09 pm

Getting Frustrated

Post by Paddon »

Hey All,

I have a program which reads in coordinates of cubes (essentially) from various external ASCII files. What is supposed to happen is the program reads in this data, then plots the cubes as required. Essentially each file is a frame (generated by an external simulation program). When I just try to read in one frame, using the following code ( I am just going to post where I know the error is located), the program works perfectly.

Code: Select all


if(ReadData(file_name)){return 0;}    // Read in the data

while(device->run())
{  
	    driver->beginScene(true, true, SColor(255,255,255,255));
		
		smgr->drawAll();
		
	for (int w=0;w<NUM_PARTICLES;w++)
          {      // loop over all the x,y,z points and plot them
           
           glColor4f(XYZ[w].f8,(1-XYZ[w].f8),0.0,0.2);
           glPushMatrix();
           glTranslatef(XYZ[w].x,XYZ[w].y,XYZ[w].z);
           glutSolidCube(0.5);
           glPopMatrix();

           }

		

		driver->endScene();
}
As I am sure you can tell, the ReadData function reads the data from a single file into the structure XYZ. Now this works fine but what I need is for the program to sequentially cycle through the files and display each frame. So I tried the following and I always get a bus error, and yes I am sure the files exist.

Code: Select all


while(device->run())
	{  
	    driver->beginScene(true, true, SColor(255,255,255,255));
		
		smgr->drawAll();
		
		sprintf(file_name,"%s%06i",name_str,i);
	    if(ReadData(file_name)){return 0;}    // Read in the data
		
		for (int w=0;w<NUM_PARTICLES;w++)
          {      // loop over all the x,y,z points and plot them
           
           glColor4f(XYZ[w].f8,(1-XYZ[w].f8),0.0,0.2);
           glPushMatrix();
           glTranslatef(XYZ[w].x,XYZ[w].y,XYZ[w].z);
           glutSolidCube(0.5);
           glPopMatrix();

           }

		

		driver->endScene();
		i++; if(i>10){i=1;}
	}


As I am not an irrlicht expert (yet :P) I am not sure where I am going wrong. I had a very very similar code running perfectly under linux ( I am using Mac OSX now btw). Anyone have any ideas? Any help would be greatly appreciated.
- Jeff Paddon
Undergraduate Research Assistant
Physics Department
St. Francis Xavier University
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I'm guessing that it crashes in either the sprintf call or in ReadData. If you are building debug you should be able to get a call stack when the app crashes and it will tell you where it is actually failing.

I'm guessing that the file_name buffer is not big enough to hold all of the characters in the file name, but I could be wrong.

Travis
Post Reply