Raw File Loader

Hello, I’m fairly new to OpenGL, and I’ve been writing a .raw loader to import models from Blender. Here’s my header file: http://docs.google.com/View?id=dd7xssbg_6d52d3qhb, and my source file: http://docs.google.com/View?id=dd7xssbg_7g28pqtd2. When I run this, I get an error saying “Unhandled exception at 0x00000000 in RawModel.exe: 0xC0000005: Access violation reading location 0x00000000.” I use Visual C++ and I know that there isn’t anything wrong with the .raw file (cube.raw), it’s fairly simple. Does anyone know why I’m getting an error, and how I can fix it? Also, if anyone could give me any recommendations of how to write a 3d loader (of basically any format) for OpenGL, that would be great, because I just figured that .raw would be easiest and I don’t really understand it very well. Thanks.

For one thing, run your code on the debugger, so you can pin point the exact line of the segfault.
Probable a too small or uninitialised array.

How do I find the error in the debugger?

In your main function, you call OpenGL functions before you have a valid rendering context. Don’t call OpenGL functions before glutInit.

Oh yeah, you’re right. I fixed that, but it still gives the same error.

I have run your code, but I don’t have a 3d raw file to test with. So now, when I run the program, I got an infinite loop somewhere and the program is not responding. Often, when a program crash at address 0x00000000, you are dereferencing a null pointer. So check very carefully the way you create and destroy your memory with new and delete.

So you’re getting the same error even without the file? I’ll have to look back at my code.

No , I have now an infinite loop in your model.render function because I don’t have a 3D model to load and I cannot verify your code farther.

Hm…I think I might just get rid of this code and write a .obj loader or some other 3d format, because I actually don’t understand .raw very well. Does anyone recommend a certain format or have a link to any tutorial for creating a loader?

This contains an OBJ and TGA Loader. Feel free to use, modify, ignore, do whatever you want with it.

Jan.

Thanks, I’ll take a look at that. I think I’ll make my own .obj loader, actually, but this should help. I’ve been looking for a good .tga loader to use as well, I haven’t been able to load any textures yet. :slight_smile:

So I’ve started writing a .obj loader, but I get another error when I do it, looking like this:

Here’s the source file:
http://docs.google.com/View?id=dd7xssbg_10dwzsr7g8
and the header file:
http://docs.google.com/View?id=dd7xssbg_8g9b5p7d6
and the .obj file:
http://docs.google.com/View?id=dd7xssbg_9gxncv3gb

You can ignore the “mtllib” and “usemtl”, I haven’t made the loader do anything with them yet. Also, I’ve used less pointers in the code, I’m using the vector class instead. If I keep running into errors I think I’ll just use Jan’s library, but I’d like to try making my own first. Any help will be greatly appreciated.

I have run your program and it crash inside the ObjModel::processVertices function when executing this instruction: delete[] &ch;

Oh yeah, you’re right. I took out all the "delete[]"s for char* and now I get a different error:

I’m looking at the code now to check the vectors for any errors.

After removing all delete[] call in your code, the program now crash at triangle.t2 = textures[strtol(pointer, &pointer, 10) - 1]; inside your bool ObjModel::processTriangle function.

Sometimes, the result of strtol(pointer, &pointer, 10) is 0, so by substracting by 1 you are doing textures[-1] and the program crash.

Yeah, I’ve just changed it to have error detection, but I forgot to make different error messages at different places :slight_smile: I’ve put up my current code on my link from before, in objloader. Now to find where the error’s coming from…

Wait, I just thought of something. How could strtol(pointer, &pointer, 10) be zero when there aren’t any zeroes in cube.obj? Or did I accidentally put it somewhere else?

First: when you call strtol(pointer,pointer, 10) this is wrong, you overwrite the variable pointer. Add a variable char *endpointer and now call strtol(pointer,&endpointer, 10);

Second: It appear that the size of the vector vector<TexturePoint2f> textures is 0, so you are accessing an empty vector and the program crash.

Yeah, I figured out that the vector size is 0, I’m working on that. But why wouldn’t strtol(pointer, &pointer, 10) work? I’m just moving further along the string. Unless strtol overwrites the second argument while still reading the first?

Oh yeah, and I changed the code on my link again, now there aren’t errors but it just shows a black window.