Page 1 of 1

Could not load png using stb_image.h

Posted: Thu Jan 05, 2023 7:09 am
by robin1201
Hello i have a problem while loading a png file using stb_image.h.
In the png.c it stucks at:

Code: Select all

Data = (UINT32*)stbi__png_load(&s, &w, &h, &l, 4, &ri); // Stucks here
I dont know what is exactly wrong.

Source code: https://github.com/rxbin1201/Bootloader

I hope anyone can help me.

Re: Could not load png using stb_image.h

Posted: Thu Jan 05, 2023 12:05 pm
by Octocontrabass
It's hard to say for sure without running your binary under a debugger, but you can't use C standard library functions like malloc() under GNU-EFI.

Re: Could not load png using stb_image.h

Posted: Fri Jan 06, 2023 1:41 pm
by robin1201
okay do you know a solution to fix this problem?

Re: Could not load png using stb_image.h

Posted: Fri Jan 06, 2023 2:00 pm
by Octocontrabass
Find any references to functions that aren't available in your environment and replace them with functions that are.

For example, there's no malloc(), but you do have AllocatePool(). The API is different, so you can't just replace malloc() with AllocatePool(), but you can come up with a wrapper function that fixes it. For example:

Code: Select all

void * my_malloc( size_t size )
{
    void * ptr;
    // note: you need to add your own error handling here.
    BS->AllocatePool( EfiLoaderData, size, &ptr );
    return ptr;
}

Code: Select all

#define STBI_MALLOC(sz)           my_malloc(sz)
If that doesn't fix the problem, use your debugger to figure out where it's getting stuck.

Re: Could not load png using stb_image.h

Posted: Fri Jan 06, 2023 2:13 pm
by robin1201
okay thanks i also did it for realloc with ReallocatePool but is there any other function because it says too few arguments to function ReallocatePool

Re: Could not load png using stb_image.h

Posted: Fri Jan 06, 2023 2:27 pm
by Octocontrabass
Huh, I didn't know GNU-EFI provides its own memory management functions. Those should work fine. There's no equivalent for realloc(), though, so you can't define STBI_REALLOC. You have to use STBI_REALLOC_SIZED instead.

Code: Select all

#define STBI_MALLOC(sz)           AllocatePool(sz)
#define STBI_FREE(p)              FreePool(p)
#define STBI_REALLOC_SIZED(p,oldsz,newsz) ReallocatePool(p,oldsz,newsz)