Crash with SDL_FreeSurface, OS X (latest testing pieces)

Hello. I’ve got a problem with the frameworks released a few days ago.
My code opens an image with IMG_Load, locks the surface, reads the
pixels, unlocks the surface and then frees it with SDL_FreeSurface -
at this point, things crash.

Here’s a backtrace:

*** malloc[1641]: error for object 0x18b8400: Incorrect checksum for
freed object - object was probably modified after being freed; break
at szone_error

Program received signal EXC_BAD_ACCESS, Could not access memory.
0x9000dd54 in small_free_list_remove_ptr ()
(gdb) bt
#0 0x9000dd54 in small_free_list_remove_ptr ()
#1 0x90001520 in szone_free ()
#2 0x3001f360 in SDL_FreeFormat ()
#3 0x30025330 in SDL_FreeSurface ()
#4 0x00006918 in load_single_texture (tex=0xf600, p_ind=0xbfffe83c)
at txm.c:549
#5 0x00006a40 in load_textures () at txm.c:573
#6 0x00006c48 in txm_load () at txm.c:604
#7 0x00003424 in init_gl () at test_txm01.c:43
#8 0x000071a8 in SDL_main (argc=1, argv=0xbffffca4) at entry.c:98
#9 0x00004270 in -[SDLMain applicationDidFinishLaunching:] (self=0x0,
_cmd=0x0, note=0x3e8) at macosx/SDLMain.m:243
#10 0x90a27aec in _nsnote_callback ()
#11 0x901da4a8 in __CFXNotificationPost ()
#12 0x901deeb8 in _CFXNotificationPostNotification ()
#13 0x90a25938 in -[NSNotificationCenter
postNotificationName:object:userInfo:] ()
#14 0x92f93380 in -[NSApplication _postDidFinishNotification] ()
#15 0x92f9326c in -[NSApplication _sendFinishLaunchingNotification] ()
#16 0x92f9349c in -[NSApplication(NSAppleEventHandling)
_handleCoreEvent:withReplyEvent:] ()
#17 0x90a7af70 in -[NSAppleEventManager
dispatchRawAppleEvent:withRawReply:handlerRefCon:] ()
#18 0x90a81808 in _NSAppleEventManagerGenericHandler ()
#19 0x9272ba10 in aeDispatchAppleEvent(AEDesc const*, AEDesc*,
unsigned long, unsigned char*) ()
#20 0x9272e858 in dispatchEventAndSendReply(AEDesc const*, AEDesc*) ()
#21 0x9272bc50 in aeProcessAppleEvent ()
#22 0x92975224 in AEProcessAppleEvent ()
#23 0x92e82484 in _DPSNextEvent ()
#24 0x92e98d2c in -[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#25 0x92ead0ac in -[NSApplication run] ()
#26 0x00004200 in CustomApplicationMain (argc=0, argv=0) at macosx/SDLMain.m:221
#27 0x00004434 in main (argc=1, argv=0xbffffca4) at macosx/SDLMain.m:315

cheers,
a1

Hello. I’ve got a problem with the frameworks released a few days ago.
My code opens an image with IMG_Load, locks the surface, reads the
pixels, unlocks the surface and then frees it with SDL_FreeSurface -
at this point, things crash.

Here’s a backtrace:

Hmmm, upon some deep investigation, I think this one might actually
be my fault. Just to be certain:

What’s in the palette struct member (in SDL_PixelFormat) if the image
is greyscale? The documentation says that palette is non-NULL for
8-bit images, but why does a greyscale image need a palette?

a1

mal content wrote:

Hello. I’ve got a problem with the frameworks released a few days ago.
My code opens an image with IMG_Load, locks the surface, reads the
pixels, unlocks the surface and then frees it with SDL_FreeSurface -
at this point, things crash.

Hmmm, upon some deep investigation, I think this one might actually be my
fault. Just to be certain:

What’s in the palette struct member (in SDL_PixelFormat) if the image
is greyscale? The documentation says that palette is non-NULL for 8-bit
images, but why does a greyscale image need a palette?

Because SDL makes no special distinction for greyscale images. An 8bpp
greyscale image is an 8bpp paletted image with a greyscale palette. Simple.

-Alex.

What’s in the palette struct member (in SDL_PixelFormat) if the image
is greyscale? The documentation says that palette is non-NULL for 8-bit
images, but why does a greyscale image need a palette?

Because SDL makes no special distinction for greyscale images. An 8bpp
greyscale image is an 8bpp paletted image with a greyscale palette. Simple.

Ok, makes sense.