Could not load png using stb_image.h

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
robin1201
Posts: 17
Joined: Sun Aug 22, 2021 3:11 pm
Location: Germany

Could not load png using stb_image.h

Post 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.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Could not load png using stb_image.h

Post 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.
robin1201
Posts: 17
Joined: Sun Aug 22, 2021 3:11 pm
Location: Germany

Re: Could not load png using stb_image.h

Post by robin1201 »

okay do you know a solution to fix this problem?
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Could not load png using stb_image.h

Post 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.
robin1201
Posts: 17
Joined: Sun Aug 22, 2021 3:11 pm
Location: Germany

Re: Could not load png using stb_image.h

Post 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
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Could not load png using stb_image.h

Post 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)
Post Reply