Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi coco cry, can't really seem to build the library and test it out on my Mac. #4

Closed
divital-coder opened this issue Jul 30, 2023 · 5 comments

Comments

@divital-coder
Copy link

Hi there coco cry,, thanks for this amazing library, which is fun to look around. Unfortunately I cant get it to build and test it out on my Mac. Wondering, if you would include "how to" steps for a basic work around.
The library overall seems pretty comprehensive, the only problem I am facing right now is , getting build error while trying to run make cmd in the root Leif directory.
ERRORS :
"/bin/leif.o" not found .....

(sorry, am not your level, but I try )

@cococry
Copy link
Owner

cococry commented Jul 30, 2023

Hey there,

Thanks for the great word first of all :) Really appreciate it.

And you probably get the error because you first need to run ./install.sh and then ./build_run

Hope this helps. And also i will definitely include a readme that explains everything with building and so on

@divital-coder
Copy link
Author

thats so sweet, will definitely check it out after running those commands, thanks for your assistance. Much appreciated.

@gruelingpine185
Copy link
Contributor

gruelingpine185 commented Jul 30, 2023

I am also on mac. I had to change some code in a Makefile for me to build the test. There is a Makefile in ./test/ and I had to replace -lglfw with $(shell pkg-config --static --libs glfw3) so that the glfw functions can be found. I was able to go under .scripts/ and run ./install to build the Lief library and the test executable. However, upon running the test executable, it crashes with a segfault.

# ...
Process 63619 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x0000000100002352 test`main(argc=1, argv=0x00007ff7bfeff478) at test.c:55:21
   52       if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
   53           printf("Failed to initialize Glad.\n");
   54       }
-> 55       LfTheme theme = lf_default_theme("../test/fonts/poppins.ttf", 64);
   56       lf_init_glfw(win_w, win_h, "../test/fonts/arial.ttf", &theme, window);   
   57       glfwSetFramebufferSizeCallback(window, resize_callback);
   58       float lastTime = 0.0f;
Target 0: (test) stopped.
(lldb) 
Process 63619 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000000000000
error: memory read failed for 0x0
Target 0: (test) stopped.

Upon further investigation (not too much because I am still learning how to debug) I found out that lf_default_theme() returns a local variable. From a quick google search I found this:

A function returns the address of a stack variable, which will cause unintended program behavior, typically in the form of a crash.

Exactly what occurs. I'm gonna try returning a heap allocated LfTheme and report my findings.


Some time later... I malloced LFTheme pointers and made a ton of conversions from dots to arrows, added dereferences where needed, and it still crashed. I also discovered that LfFont had the same issue. Upon repeating said process for LfFont, it still crashes. Thankfully at the same function: lf_default_theme(). Unfortunately, this problem seems like a massive undertaking and this is the extent of my efforts. I hope that a fix is found.

@ggcow
Copy link

ggcow commented Aug 2, 2023

uint8_t bitmap[tex_width * tex_height];
uint8_t bitmap_4bpp[tex_width * tex_height * 4];

These variable-length arrays can be quite large, it is safer to use malloc/free here. It might help solve the issue.

@cococry
Copy link
Owner

cococry commented Aug 3, 2023

you're right. will change that, so that it allocates on the heap

@cococry cococry closed this as completed Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants