OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Mar 18, 2024 10:32 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Could not load png using stb_image.h
PostPosted: Thu Jan 05, 2023 7:09 am 
Offline

Joined: Sun Aug 22, 2021 3:11 pm
Posts: 17
Location: Germany
Hello i have a problem while loading a png file using stb_image.h.
In the png.c it stucks at:

Code:
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.


Top
 Profile  
 
 Post subject: Re: Could not load png using stb_image.h
PostPosted: Thu Jan 05, 2023 12:05 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
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.


Top
 Profile  
 
 Post subject: Re: Could not load png using stb_image.h
PostPosted: Fri Jan 06, 2023 1:41 pm 
Offline

Joined: Sun Aug 22, 2021 3:11 pm
Posts: 17
Location: Germany
okay do you know a solution to fix this problem?


Top
 Profile  
 
 Post subject: Re: Could not load png using stb_image.h
PostPosted: Fri Jan 06, 2023 2:00 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
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:
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:
#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.


Top
 Profile  
 
 Post subject: Re: Could not load png using stb_image.h
PostPosted: Fri Jan 06, 2023 2:13 pm 
Offline

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


Top
 Profile  
 
 Post subject: Re: Could not load png using stb_image.h
PostPosted: Fri Jan 06, 2023 2:27 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
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:
#define STBI_MALLOC(sz)           AllocatePool(sz)
#define STBI_FREE(p)              FreePool(p)
#define STBI_REALLOC_SIZED(p,oldsz,newsz) ReallocatePool(p,oldsz,newsz)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group