Skip to main content
GameDev.net gamedev.net
🔒 Locked

Model Loading

Started by dbzprogrammer Jan 16, 2006 at 10:11 AM 12 replies 1.5k views
Original Post
dbzprogrammer
dbzprogrammer
I have a problem, which many people suggest something that works (verified), but I don't get why. I take a standard model file around 100 Kb or so, open it with a FILE* fp. I read it in piece by piece, but part of the way through, it just stops. Starts repeating itself in one place. When I load the whole file into a buffer, and take piece by piece out, I don't get this problem. The question is, why?
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Illco
Illco
There could be many reasons -- some of them being:

- is the file format what you think it is?
- is the file correct in itself?
- is your code correct in reading it?

There is no way to tell unless you become more specific about the file, file format and especially reading code.

Illco
dbzprogrammer
dbzprogrammer
Quote:
Original post by Illco
There could be many reasons -- some of them being:

- is the file format what you think it is?
- is the file correct in itself?
- is your code correct in reading it?

There is no way to tell unless you become more specific about the file, file format and especially reading code.

Illco


- is the file format what you think it is?

.3ds Yes, very much so. I've even copied .3ds files that worked in other 3ds loaders.

- is the file correct in itself?

Yes

- is your code correct in reading it?

Renderer works fine, the .3ds file loader was almost a complete copy as space simulators, except with dynamic arrays instead of static.

I spent a couple weeks on the thing before being unable to conceal my anger against memory. It would load everything fine, and then just get stuck on some stupid thing. No matter what I did, it stayed on that same piece.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
steven katic
steven katic
You need post the code that is "repeating itself in one place" to really get any more help.
Axiverse
Axiverse
Also check that you opened the file in binary and not text.
dbzprogrammer
dbzprogrammer
Quote:
Original post by Axiverse
Also check that you opened the file in binary and not text.


... Yes. Part of it is that I can't exactly find the code. I'm not looking for a code solution, I'm looking for why it happened... If extreamly neccessary, then I guess I could try re-typing it.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Endar
Endar
If I'm understanding correctly, there's an infinite loop of some sort?

If so, debugger.

In most debugger's there should be an option called "Run to line" or something similar.

Basically start from the start and use the "run to line" option when your cursor is after every major block of code. When it gets stuck, close the program and start again, this time knowing which block of code it stops at. Then just narrow it down until you find the line.

If I'm not understanding correctly, and it's not an infinite loop, step through it the way I described and just find the point at which it begins repeating. Then, post that code here and we could probably help a bit.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
dbzprogrammer
dbzprogrammer
It's a while ("not at end of file loop").
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Endar
Endar
So, it never gets to the end of the file? Or it just repeats a single value for a while and then cuts out?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
dbzprogrammer
dbzprogrammer
Stops on part of the file (random) and then repeats it non stop.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
JavaMava
JavaMava
so say the file is 1,2,6,3,8,5,7,4, ect.

Your code reads it in and it stops on a random part, say 8 and then just keeps reading it?

I'm just trying to clarify what your saying.
Symphonic
Symphonic
I'm going to assume you don't really mean really random, it may be random up to the file. So you couldn't predict what it would do on a particular file, but it will do the same thing every time.

This is a standard problem when building a text file parser (not using YAK/FLEX), that there is a path through your read loop that doesn't consume any input, and preserves the parser state in such a way that the same path is taken again next time.

Comb the loop, and make sure that input is always consumed.
Geordi
George D. Filiotis
dbzprogrammer
dbzprogrammer
Quote:
Original post by JavaMava
so say the file is 1,2,6,3,8,5,7,4, ect.

Your code reads it in and it stops on a random part, say 8 and then just keeps reading it?

I'm just trying to clarify what your saying.


Yes
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
benishor
benishor
Quote:
Original post by dbzprogrammer
I have a problem, which many people suggest something that works (verified), but I don't get why. I take a standard model file around 100 Kb or so, open it with a FILE* fp. I read it in piece by piece, but part of the way through, it just stops. Starts repeating itself in one place. When I load the whole file into a buffer, and take piece by piece out, I don't get this problem. The question is, why?




you may be having problems with your fopen/fseek/fread skills :) the suggestion mentioned above has the speed advantage and also the ease of jumping at different offsets at no cost.

a 3ds file consists of several chunks of information which you need to skip if you don't read. in order to do so, you need to take the chunk length information from it's header and jump forward as many bytes as needed.

your problem most likely lies in reading the type of data from the file. I think I remember there were shorts used. the best way to track this down would be to print each chunk's ID / length and the offset in file you are trying to read at.
---novocaine thru yer veinz

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.