• 13
• 15
• 27
• 9
• 9

# file-streaming,

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

## Recommended Posts

Alas, after fateful days of debugging and refactoring, and not a chance in hope I'll be able to track down an elusive bug, I decided to check the logfiles. I made a nice neat little error logger, so now its time to go through it and see if it yeilds anything valuable. Ah HA!
Created file streams
assigning *num_lights

Position:[ -188.635, 110.917, -194.239]
Color:[ 213, 208, 198]
Position:[ 215.097, 110.917, -194.239]
Color:[ 255, 198, 198]
Position:[ -8.89714, 110.917, 350.853]
Color:[ 198, 211, 255]

assigning *num_materials

Material Name: walls
Creating Diffuse Texture: data\ConcreteCast-In-Place.bmp
No opacity texture
No normal texture
No bump texture
Material name: walls

Material Name: box2
Creating Diffuse Texture: data\STEELPLT.bmp
No opacity texture
No normal texture
No bump texture
Material name: box2

Material Name: pipe2
Creating Diffuse Texture: data\fx3_Panels_4.bmp
No opacity texture
No normal texture
No bump texture
Material name: pipe2

Material Name: floor
Creating Diffuse Texture: data\MtlPlat2.bmp
No normal texture
No bump texture
Material name: floor

Material Name: boxes
Creating Diffuse Texture: data\Crateold.bmp
No opacity texture
No normal texture
No bump texture
Material name: boxes

No diffuse texture
No opacity texture
Material name: solid_color

done

assigning *num_objects

match:0 walls
found and linked material to object
material_name:walls node->data->name:walls

match:-1 walls
match:1 box2
match:0 pipe2
found and linked material to object
material_name:pipe2 node->data->name:pipe2

match:-1 walls
match:1 box2
match:0 pipe2
found and linked material to object
material_name:pipe2 node->data->name:pipe2

match:-1 walls
match:1 box2
match:0 pipe2
found and linked material to object
material_name:pipe2 node->data->name:pipe2

match:-1 walls
match:0 box2
found and linked material to object
material_name:box2 node->data->name:box2
Tðä	Tðä	/ÇB§øCFTtÃ4U†?sç¿@Dß?            on: 1
„™Á¨øCK—–Ã~	:  @@@ß?            addiï	4  €?"F›(7
„:@
9@
Tðä	Tðä	²ø	Ã¨øCHTtÃ |	: kD; :             11
adding p²ø	Ã ß‡BHTtÃ5U†? kD; ð:             polygon: 14£„™Áß‡BGTtÃ5U†?  @@ ð:            16
: 18

match:-1 walls
match:0 box2
found and linked material to object
material_name:box2 node->data->name:box2

match:-1 walls
match:1 box2
match:-1 pipe2
match:0 floor
found and linked material to object
material_name:floor node->data->name:floor

match:-1 walls
match:1 box2
match:-1 pipe2
match:-1 floor
match:0 boxes
found and linked material to object
material_name:boxes node->data->name:boxes

match:-1 walls
match:1 box2
match:-1 pipe2
match:-1 floor
match:0 boxes
found and linked material to object
material_name:boxes node->data->name:boxes

match:-1 walls
match:1 box2
match:-1 pipe2
match:-1 floor
match:0 boxes
found and linked material to object
material_name:boxes node->data->name:boxes

match:-1 walls
match:1 box2
match:-1 pipe2
match:-1 floor
match:0 boxes
found and linked material to object
material_name:boxes node->data->name:boxes

match:-1 walls
match:1 box2
match:-1 pipe2
match:-1 floor
match:0 boxes
found and linked material to object
material_name:boxes node->data->name:boxes


what worries me the most is
found and linked material to object
material_name:box2 node->data->name:box2
Tðä	Tðä	/ÇB§øCFTtÃ4U†?sç¿@Dß?            on: 1
„™Á¨øCK—–Ã~	:  @@@ß?            addiï	4  €?"F›(7
„:@
9@
Tðä	Tðä	²ø	Ã¨øCHTtÃ |	: kD; :             11
adding p²ø	Ã ß‡BHTtÃ5U†? kD; ð:             polygon: 14£„™Áß‡BGTtÃ5U†?  @@ ð:            16
: 18

simply put: WTF?! I'm using streams for the error log, and I have NO idea how I could bork it that badly. Does anyone have any insight at all as to how it possible to bamboozle a stream like this? I'm completely lost as to how I've managed to mess this up. Also, all of the data read at that point is also corrupted. I first noticed to problem when I was trying to generate gl display lists and I could access the data. The same data which is being read when the errlog goes kapoot. Thanks in advance. Cheers

##### Share on other sites
Quote:
 Original post by aaron_dsAlas, after fateful days of debugging and refactoring, and not a chance in hope I'll be able to track down an elusive bug,

Quote:
 I'm completely lost as to how I've managed to mess this up.Also, all of the data read at that point is also corrupted. I first noticed to problem when I was trying to generate gl display lists and I could access the data. The same data which is being read when the errlog goes kapoot.

Its just a long shot (because I dont know what your logging code looks like or what the original problem is), but is it possible that the logger is fine and is printing corrupted data - which is the cause of your original problem?

Id step through the debugger to verify this and map the memory while going through the routines.

Hope that helps..

#dth-0

##### Share on other sites
Quote:
 Original post by aaron_dsAlas, after fateful days of debugging and refactoring, and not a chance in hope I'll be able to track down an elusive bug,

Quote:
 I'm completely lost as to how I've managed to mess this up.Also, all of the data read at that point is also corrupted. I first noticed to problem when I was trying to generate gl display lists and I could access the data. The same data which is being read when the errlog goes kapoot.

Its just a long shot (because I dont know what your logging code looks like or what the original problem is), but is it possible that the logger is fine and is printing corrupted data - which is the cause of your original problem?

Id step through the debugger to verify this and map the memory while going through the routines.

Hope that helps..

#dth-0

##### Share on other sites
/*build polygon linked list*/    for(int i=0; i<*num_polygons; i++){      errlog<<"adding polygon: "<<i<<"\n";      file>>object.polygon_list.append();    }

file is an ifstream.

overload the >> operator for streaming filedata into polygons
ifstream& operator>>(ifstream& file, POLYGON& poly){  file>>poly.normal;  file>>poly.verts[0];  file>>poly.verts[1];  file>>poly.verts[2];  return file;}

ifstream& operator>>(ifstream& file, POINT3f& point){  if(!&point || !&file)    return file;  file.read((char*)(&(point.x)), sizeof(float));  file.read((char*)(&(point.y)), sizeof(float));  file.read((char*)(&(point.z)), sizeof(float));  return file;}

I'm confused as to why everything is read fine until a point, then corrupted, then read fine after that.

##### Share on other sites
could lots of things...

memory corruption would be my guess. Are you allocating enough buffer space for your data? If you think you do, try to allocate the same amount plus some extra, and run the test again. if the memory corruption happens further down, then your memory allocator could be not working properly. Although, you should get an access violation at some point.

when you create the ifstream, do you create the buufer allocation before? something like

char* buffer;
ifstream file;

when you do file.read((char*)(&(point.x)), sizeof(float));, can't you do fille>>point.x; directly?

when you read vectors, do sanity checks, like check the exponent part of the vector you read, vaildate floats by checking if the exponent part is corrupted.

if ((((*(int *)&float_number) >> 23) & 0x8F) > 32)
Assert("Invalid floating point number");

not sure if this is correct, but someone will correct me on that.

Could also be that your importer is missing something about the object format. maybe this object as something particular about it, like reflection maps, or flags, and you missed something, therefore, all the data is offset in the file. But I doubt.

when reaching object4, flush the stream, check the file, and step by step through the log outputs, while flushing the log buffer everytime you output something.

I'm just guessing though....