View Full Version : Raw File Loader
02-27-2010, 01:54 PM
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. (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.
02-27-2010, 01:59 PM
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.
02-27-2010, 02:01 PM
How do I find the error in the debugger?
02-27-2010, 02:26 PM
In your main function, you call OpenGL functions before you have a valid rendering context. Don't call OpenGL functions before glutInit.
02-27-2010, 02:29 PM
Oh yeah, you're right. I fixed that, but it still gives the same error.
02-27-2010, 02:41 PM
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.
02-27-2010, 02:43 PM
So you're getting the same error even without the file? I'll have to look back at my code.
02-27-2010, 02:54 PM
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.
02-28-2010, 05:44 AM
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 (http://www.artifactgames.de/Code/Loader.zip) contains an OBJ and TGA Loader. Feel free to use, modify, ignore, do whatever you want with it.
02-28-2010, 06:14 AM
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. :)
02-28-2010, 11:29 AM
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:
and the header file:
and the .obj file:
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.
02-28-2010, 12:32 PM
I have run your program and it crash inside the ObjModel::processVertices function when executing this instruction: delete &ch;
02-28-2010, 12:45 PM
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.
02-28-2010, 12:47 PM
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.
02-28-2010, 01:00 PM
Sometimes, the result of strtol(pointer, &pointer, 10) is 0, so by substracting by 1 you are doing textures[-1] and the program crash.
02-28-2010, 01:13 PM
Yeah, I've just changed it to have error detection, but I forgot to make different error messages at different places :) I've put up my current code on my link from before, in objloader. Now to find where the error's coming from...
02-28-2010, 01:15 PM
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?
02-28-2010, 01:57 PM
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.
02-28-2010, 02:12 PM
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.
02-28-2010, 02:29 PM
Ok, it seem that strtol(pointer, &pointer, 10); or strtol(pointer, &endpointer, 10); give the same result. I read the man page of strtol and the example program use strtol(pointer, &endpointer, 10); for error detection. So no problem with the instruction strtol(pointer, &pointer, 10); if you don't check for error.
02-28-2010, 03:04 PM
It works now, I just had to fix a couple of bugs, because the program wasn't reaching the part where triangles are added to the "triangles" vector. Now I just need to make functions for mtllib and usemtl, and add some other features :) I uploaded the code, by the way. Thanks for your help! Now I can import models from Blender.
02-28-2010, 03:14 PM
Good to know that your program run fine now.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.