Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

keethrus

free( ptr ) ending program prematurely?

This topic is 5713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

at the end of my program, when i free a certain image, my program just ends. SDL reports "Fatal signal: Segmentation Fault (SDL Parachute Deployed)". the pointer isnt null, and its not freed anywhere beforehand. why would free be causing this error and how do i stop it? or how can i better find out whats causing the error? - jeremiah inlovewithGod.com

Share this post


Link to post
Share on other sites
Advertisement
is the pointer being initialised to start with?

is it allocated with new and free''d without delete... that''ll give you grief

Share this post


Link to post
Share on other sites
the ptr points to my image struct that contains three values, Uint32 width, Uint32 height, and Uint8 *pixels. a function called "createImage" allocates memory for a pointer to an instance of the struct. then allocates memory for the Uint8 *pixels and initializes it as well. i know its successful because in the main loop, my drawImage function successfully draws it to screen. at the end of my program i have a freeImage function that frees the Uint8 *pixels, and then frees the entire struct.

void freeImage( struct myImage *ptr )
{
myIMAGE_numOfImages--;
free( ptr->pixels );
free( ptr );
}

other images are successfully loaded, drawn, and freed in the exact same manner. its only one image that causes the program to end when it tries to free its ptr->pixels. but i know its loaded successfully because i can draw it to screen.

this problem is baffling me.

- jeremiah


inlovewithGod.com

Share this post


Link to post
Share on other sites
Are you sure you didn''t touch that pointer after allocating the memory? Like incrementing it, or something?
Are you sure nothign access that memory, after you freed it?
Does it crash exactly when you free it, or after that?

Height Map Editor | Eternal lands

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!