View Single Post
  #4   (View Single Post)  
Old 18th April 2011
thirdm thirdm is offline
Spam Deminer
 
Join Date: May 2009
Posts: 248
Default

Sorry, nothing's jumping out at me. rcFlora is indeed an array of structs (SDL_Rect is a typedef of a struct according to its man page) within your GameRes struct. When you do your malloc it should get its memory as long as malloc succeeds (you ought to check btw -- malloc returns NULL if it fails to find memory for you). I don't see a problem there.

All I can think is that maybe you do a free on gr sometime before you use it this last time. Either that or you've got bounds errors or use after free elsewhere that have corrupted your heap and you're seeing some kind of nasty action at a distance effect. I wonder a little about temp in the resource load function. I assume IMG_Load allocates and SDL_FreeSurface releases it. You wouldn't be inadvertently assigning it to something and then using the object it pointed to after it was freed would you?

Maybe now is the time to run this through gdb and get a stack trace at the point where it gets the (I'm guessing) segv signal? That's often a good clue. Also, you may want to read the man page for malloc to see what kind of debugging options it has. I know OpenBSD has some nice options you can set with an environmental variable to help debug memory problems by "failing fast" in various ways. Probably the other BSDs have something similar.
Reply With Quote