- I'm using plain ANSI C
- Here is the bulk of relevant source code, and you can see everything else up there as needed: http://github.com/freemancw/Exact3D/blo ... odel_ase.c
- Here is a test ASE file that produces the bug: http://student.cs.appstate.edu/freemancw/junk/test.ASE
- If I run the code inside of eclipse with the gdb debugger, it works fine. If I run the executable, it crashes.
- I have debugging code that prints out the values of all of the fields of a given model. For test.ASE, the problematic area produces the following.
Code: Select all
Face Count: 2 <- this is correct ======================================================= Face ID: 2 <-- should be 0 A: 8, B: 2, C: 7404232, AB: 7372608, BC: 7404352, CA: 7404504 <- all of these values are wrong Smoothing Group: 1 <- from here on everything is correct Material ID: 0 Face Normal: X = 0.000000, Y = 0.000000, Z = 1.000000 Face ID: 1 A: 1, B: 3, C: 0, AB: 1, BC: 0, CA: 1 Smoothing Group: 1 Material ID: 0 Face Normal: X = 0.000000, Y = 0.000000, Z = 1.000000
Tracking down memory allocation error
Tracking down memory allocation error
I've been writing an ASE model loader for a couple of weeks now, and a single bug has eluded me for almost a week. I'm not exactly positive what is causing it, so I'll just provide the clues I'm aware of, and see if anyone with more experience can help:
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Tracking down memory allocation error
Have you tried running it through valgrind?
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Tracking down memory allocation error
Okay, did a quick check. The culprit seems to be at line 131:
EDIT: materialList.materialList is a pointer and you never malloc()'ed memory for it. Where can I send my invoice to?
Code: Select all
materialList.materialList[currentMaterialID].materialID = currentMaterialID;
Re: Tracking down memory allocation error
No sir, I should also mention I'm running on Win7. Which would be the best tool to check out, maybe IBM's Purify?
edit: haha, not so fast! are you looking at the correct file?
edit: haha, not so fast! are you looking at the correct file?
Last edited by Kaz on Thu Apr 04, 2013 2:39 am, edited 1 time in total.
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Tracking down memory allocation error
Ah wait, wrong branch.
Line 282: you realloc() without assigning the result. Pro tip: you don't need to call malloc() separately, realloc(NULL) does the same thing.
As to purify, it's pretty good but not nearly as thorough as valgrind is. Valgrind runs your code in a kind of emulator that allows it to track every instruction and every byte read or written. It's truly awesome.
Line 282: you realloc() without assigning the result. Pro tip: you don't need to call malloc() separately, realloc(NULL) does the same thing.
As to purify, it's pretty good but not nearly as thorough as valgrind is. Valgrind runs your code in a kind of emulator that allows it to track every instruction and every byte read or written. It's truly awesome.
Re: Tracking down memory allocation error
KAAAAAHHHHNNN!!!
Thanks a million, I'm pretty sure that solved my problem! For some reason I wasn't thinking that realloc returned a pointer.... dunno why
Thanks a million, I'm pretty sure that solved my problem! For some reason I wasn't thinking that realloc returned a pointer.... dunno why

-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Tracking down memory allocation error
I assume you use Visual Studio? If you compile with `gcc -Wall`, it'll complain about stuff like this.
Re: Tracking down memory allocation error
I'm using Mingw with eclipse