Issue

Hi,

Damn it it never works !
So now I am using SDl_Image and I get a weird error when loading a png :

sprite = IMG_Load(“test.png”);

but sprite is NULL because of the following :

lib.png_set_read_fn =
(void (*) (png_structp, png_voidp, png_rw_ptr))
SDL_LoadFunction(lib.handle, “png_set_read_fn”);
if ( lib.png_set_read_fn == NULL ) {
SDL_UnloadObject(lib.handle);
return -1;
}

SDL_LoadFunction returns NULL.

When I trace I can see :

void *SDL_LoadFunction(void *handle, const char *name)
{
void *symbol = NULL;
const char *loaderror = “Unknown error”;

#if defined(_WIN32_WCE)
char errbuf[512];
int length = SDL_strlen(name);

wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t));
wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t));

memset(name_t, 0, length+1 * sizeof(name_t));
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length);
RETAILMSG(1, (L"SDL_LoadFunction: name_t = [%s]\r\n", name_t));


}

I have also added a memset to be sure I don’t have invalid data

SDL_LoadFunction: name_t = [png_create_info_struct]
SDL_LoadFunction: name_t = [png_create_read_struct]
SDL_LoadFunction: name_t = [png_destroy_read_struct]
SDL_LoadFunction: name_t = [png_get_IHDR]
SDL_LoadFunction: name_t = [png_get_io_ptr]
SDL_LoadFunction: name_t = [png_get_tRNS]
SDL_LoadFunction: name_t = [png_get_valid]
SDL_LoadFunction: name_t = [png_read_image]
SDL_LoadFunction: name_t = [png_read_info]
SDL_LoadFunction: name_t = [png_read_update_info]
SDL_LoadFunction: name_t = [png_set_expand]
SDL_LoadFunction: name_t = [png_set_gray_to_rgb]
SDL_LoadFunction: name_t = [png_set_packing]
SDL_LoadFunction: name_t = [png_set_read_fn?]

and I really don’t undertand why there is a space at the end of
png_set_read_fn
because in SDl_Image string is OK…

I am testing on a PPC2003 emulator.

Hello Vincent,

wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t));
memset(name_t, 0, length+1 * sizeof(name_t));
I have also added a memset to be sure I don’t have invalid data

You should use sizeof(wchar_t) for that memset, not sizeof(name_t), which is
sizeof(wchar_t *).
Of course, that does not fix your original problem. But it might save you from
additional errors and confusion.

SDL_LoadFunction: name_t = [png_set_read_fn?]
and I really don’t undertand why there is a space at the end

That seems to be a special character, not the regular space. At first I saw
three bytes in your text that looked like memory garbage, because Thunderbird
never gets the encoding right. After switching to UTF-8, a narrow space was
displayed.
This message is supposed to be in UTF-8 as well, btw.

However, I have no idea why the string is causing trouble. Apart from the
memset, the code looks ok to me.

I’m unsure about the last parameter of MultiByteToWideChar, though. Should it
include the terminating null character, i. e. be length+1? MSDN only says, if it
is passed as 0, the function will return the required buffer size including the
null character. That way you can allocate your buffer dynamically and then call
the function again. Would they force us to subtract 1 from the returned buffer
size for that second call?

What I’d suggest first: Check the return value of MultiByteToWideChar. It is the
number of characters written to the buffer. 0 indicates an error. In that case,
simply don’t call GetProcAddress, leaving symbol==NULL. Then FormatMessage
called afterwards will give you details on the MultiByteToWideChar error.

Have you made several tries, receiving that extraneous space every time? This
might give a hint on whether it is memory garbage you are seeing (indicating
something like a buffer overrun error).
“Random” errors can be quite stable given constant input. Try changing some
details, like increasing the size for SDL_malloc and so on.

Does your program use threads (at the time when that loading occurs, or before)?

Are you using SDL 1.2 or 1.3?

Bye
Martin

Hello Vincent,

wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t));
memset(name_t, 0, length+1 * sizeof(name_t));
I have also added a memset to be sure I don’t have invalid data

You should use sizeof(wchar_t) for that memset, not sizeof(name_t), which
is
sizeof(wchar_t *).
Of course, that does not fix your original problem. But it might save you
from
additional errors and confusion.

Yes sorry I have coded too quickly but I know differences between pointers
and types

SDL_LoadFunction: name_t = [png_set_read_fn?]
and I really don’t undertand why there is a space at the end

That seems to be a special character, not the regular space. At first I
saw

three bytes in your text that looked like memory garbage, because
Thunderbird
never gets the encoding right. After switching to UTF-8, a narrow space
was

displayed.
This message is supposed to be in UTF-8 as well, btw.

I don’t know how to change my defaul webmail encoding(I will investigate
this).

However, I have no idea why the string is causing trouble. Apart from the

memset, the code looks ok to me.

I’m unsure about the last parameter of MultiByteToWideChar, though.
Should
it
include the terminating null character, i. e. be length+1? MSDN only
says,
if it
is passed as 0, the function will return the required buffer size
including
the
null character. That way you can allocate your buffer dynamically and
then
call
the function again. Would they force us to subtract 1 from the returned
buffer
size for that second call?

What I’d suggest first: Check the return value of MultiByteToWideChar. It
is the
number of characters written to the buffer. 0 indicates an error. In that
case,
simply don’t call GetProcAddress, leaving symbol==NULL. Then
FormatMessage
called afterwards will give you details on the MultiByteToWideChar error.

First don’t know if it’s the case but I found this article
http://support.microsoft.com/?scid=kb%3Ben-us%3B941238&x=13&y=16

Then it seems that MultiByteToWideChar returns 0 and I get the following
message :
Error The data area passed to a system call is too small

So I can confirm that you need to pass length+1.

Have you made several tries, receiving that extraneous space every time?
This
might give a hint on whether it is memory garbage you are seeing
(indicating
something like a buffer overrun error).
“Random” errors can be quite stable given constant input. Try changing
some

details, like increasing the size for SDL_malloc and so on.

Does your program use threads (at the time when that loading occurs, or
before)?

Are you using SDL 1.2 or 1.3?

I am using SDL 1.2 from SVN with patch sent by someone on this list to fix
a compilation
problem.
And I am testing the project testalpha where I have modified the loaded
bitmap (a png instead of a bmp).On Sat, 25 Apr 2009 11:23:13 +0200, Martin <name.changed.by.editors at online.de> wrote:

Vincent R. wrote:

I’m unsure about the last parameter of MultiByteToWideChar, though.
Should it include the terminating null character, i. e. be length+1?

What I’d suggest first: Check the return value of MultiByteToWideChar. It
is the number of characters written to the buffer. 0 indicates an error.

First don’t know if it’s the case but I found this article
http://support.microsoft.com/?scid=kb%3Ben-us%3B941238&x=13&y=16

I think that fix addresses a different issue.

Then it seems that MultiByteToWideChar returns 0 and I get the following
message :
Error The data area passed to a system call is too small
So I can confirm that you need to pass length+1.

So, if you pass length+1, does SDL_LoadFunction work now? Can you access
png_set_read_fn?

Off-topic:

I don’t know how to change my defaul webmail encoding(I will investigate
this).

No need to, the problem is not on your side. It’s my Thunderbird that is either
misconfigured or has a bug. When I receive a UTF-8 encoded mail from anyone, I
always have to switch encodings manually.

The encoding is given in the mail header. Thunderbird even writes such a header
line itself, but later completely ignores it (i. e. even my own mail doesn’t get
displayed correctly).

Bye
Martin

Vincent R. wrote:

I’m unsure about the last parameter of MultiByteToWideChar, though.
Should it include the terminating null character, i. e. be length+1?

What I’d suggest first: Check the return value of MultiByteToWideChar.
It
is the number of characters written to the buffer. 0 indicates an
error.

First don’t know if it’s the case but I found this article
http://support.microsoft.com/?scid=kb%3Ben-us%3B941238&x=13&y=16

I think that fix addresses a different issue.

Then it seems that MultiByteToWideChar returns 0 and I get the
following

message :
Error The data area passed to a system call is too small
So I can confirm that you need to pass length+1.

So, if you pass length+1, does SDL_LoadFunction work now? Can you access
png_set_read_fn?

Yes after the modification everything works fine.On Sat, 25 Apr 2009 15:12:41 +0200, Martin <name.changed.by.editors at online.de> wrote:

Off-topic:

I don’t know how to change my defaul webmail encoding(I will investigate
this).

No need to, the problem is not on your side. It’s my Thunderbird that is
either
misconfigured or has a bug. When I receive a UTF-8 encoded mail from
anyone, I
always have to switch encodings manually.

The encoding is given in the mail header. Thunderbird even writes such a
header
line itself, but later completely ignores it (i. e. even my own mail
doesn’t get
displayed correctly).

Bye
Martin


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