Skip to main content
gamedev.net
🔒 Locked

bloody memory bug

Started by llvllatrix Apr 26, 2003 at 9:50 PM 8 replies 650+ views
Original Post
llvllatrix
llvllatrix
What instances would this code produce an illegal operation?
  
type * darray;
darray = new type [size];

//bug occurs here:

if(darray)
    delete [] darray;
  
Filami
Filami
there is 2 things that you could test:

-run until the line of creation and see what is the number inside the size. if it is odd, then probrably there is the error.
-try to delete the [] from the delete [] darray. Chack if it works


Techno Grooves
Techno Grooves
snisarenko
snisarenko
Can a pointer return a true or false statement ? I mean r u allowed to put pointers in boolean expressions ? Because thats what u r doing: --------> if(darray)

______________________________
My Website: [link]www.antondev.tk[/link]
or directly at http://home.attbi.com/~antonweb/
"I''ve read about...doom being used to manage unix programs(you "kill" the processes)" dede
llvllatrix
llvllatrix
quote:


-run until the line of creation and see what is the number inside the size. if it is odd, then probrably there is the error.




Would it really give an error if it were odd? Why?
Beer Hunter
Beer Hunter
quote:
Original post by llvllatrix
Would it really give an error if it were odd? Why?
I think Filami means "odd" as in "unusual".
Darkor
Darkor
I don''t see how that will give an error if the type was basic. However, if it is one of your class types then your error might be somewhere else.

Run your debugger to find the exact line where your program gives the error.
Wavarian
Wavarian
try doing this:

type *darray = NULL;
darray = new type[SIZE];
if(darray) delete[] darray;

ive noticed that if the "new type[SIZE]" part fails, it doesnt set darray to NULL. thus darray will alway point to a random non-null memory address.
llvllatrix
llvllatrix
Its the oddest thing. Actually the code is in a milkshape exporter that i wrote. Its just for this one model that it screws up. Ultimately, the file it produces is fine. Its just that for this one file, when i try to delete the triangle array, i get the illegal opperation.

I got the file though...really all i cared about but i was just wondering if there was some wierd thing i didn''t know about that was messing with my code...probably just my pc - its starting to die now, going to have to format soon

Topic Locked

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

Sign in to reply to this topic.