Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

SDL_FreeSurface and segfault

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 killwin   Members   

101
Like
0Likes
Like

Posted 23 October 2012 - 01:59 AM

Hello,

I I have a verry bad problem.

In my draw.h :

[source lang="cpp"]class CDraw : public CGraphic{ public : // constructor CDraw(const float& coef_resol_);...private : SDL_Surface *destimg;}[/source]

In my draw.cpp :

[source lang="cpp"]CDraw::CDraw(const float& coef_resol_) : CGraphic({0, 0}, coef_resol_), texture(NULL), destimg(NULL) {}void CDraw::~CDraw() { if(surface) SDL_FreeSurface(surface);/* segfault with it :-( */ if(destimg) SDL_FreeSurface(destimg);}[/source]

Well in all lines in draw.cpp, i'm not working with destimg. i commented all destimg. I have only destimg(NULL) and if(destimg) SDL_FreeSurface(destimg);

With gdb, with a break point before the if(destimg) i have :

(gdb) print destimg
$2 = (SDL_Surface *) 0x766177

And next a SEGFAULT.

I don t understand, thanks

#2 BitMaster   Members   

8647
Like
0Likes
Like

Posted 23 October 2012 - 03:01 AM

Two likely scenarios:
1) You write over the bounds of memory somewhere, thereby trashing the CDraw object and writing an invalid destimg pointer over the 0.
2) You are destroying an invalid CDraw object. Either because you delete the same object twice or you delete an uninitialized pointer.

#3 killwin   Members   

101
Like
0Likes
Like

Posted 23 October 2012 - 07:23 AM

Solved thanks, i found a line with surface = destimg. Then i was calling SDL_FreeSurface two times on the same pointer.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.