[SDL_Image]LoadImageFromRWops can't work on Iphone

I’m confused by the below codes in IMG_UIImage.m:
CGImageRef image_ref = NULL;

do
{
bytes_read = SDL_RWread(rw_ops, temp_buffer, 1, block_size);
[ns_data appendBytes:temp_buffer length:bytes_read];
} while(bytes_read > 0);

if(NULL == image_ref)
{
	return NULL;
}

The variable that named image didn’t be assinged any value.
I changed the codes as below, it can work now:
do
{
bytes_read = SDL_RWread(rw_ops, temp_buffer, 1, block_size);
[ns_data appendBytes:temp_buffer length:bytes_read];
} while(bytes_read > 0);

ui_image = [[UIImage alloc] initWithData:ns_data];

if(NULL == ui_image)
{
	return NULL;
}-- 

View this message in context: http://old.nabble.com/-SDL_Image-LoadImageFromRWops-can't-work-on-Iphone-tp26401843p26401843.html
Sent from the SDL mailing list archive at Nabble.com.

Yeah, this is a bug. Copy & Paste anti-pattern strikes again. I think
the best solution is to remove both image_ref and the NULL check
completely. (There is a second bug that will memory leak if the
function early returns and ns_data will never be NULL regardless.)

Sam, patch attached.

-EricOn 11/17/09, Alex Cheng <alex.cj at gmail.com> wrote:

I’m confused by the below codes in IMG_UIImage.m:
CGImageRef image_ref = NULL;

do
{
bytes_read = SDL_RWread(rw_ops, temp_buffer, 1, block_size);
[ns_data appendBytes:temp_buffer length:bytes_read];
} while(bytes_read > 0);

if(NULL == image_ref)
{
return NULL;
}
The variable that named image didn’t be assinged any value.
I changed the codes as below, it can work now:
do
{
bytes_read = SDL_RWread(rw_ops, temp_buffer, 1, block_size);
[ns_data appendBytes:temp_buffer length:bytes_read];
} while(bytes_read > 0);

ui_image = [[UIImage alloc] initWithData:ns_data];

if(NULL == ui_image)
{
return NULL;
}


View this message in context:
http://old.nabble.com/-SDL_Image-LoadImageFromRWops-can't-work-on-Iphone-tp26401843p26401843.html
Sent from the SDL mailing list archive at Nabble.com.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: IMG_UIImage_m.patch
Type: application/octet-stream
Size: 833 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20091118/847f4c2a/attachment.obj