-
Notifications
You must be signed in to change notification settings - Fork 18
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
OpenFontRender support for Teensy 4.1 #45
Comments
I have the same issue with esp-idf v4.4 |
Changing the strncpy to memcpy seems to solve the issue. But I don't know how good of a fix this is. There could be a better method. |
Hello, unfortunately, the issue persists. I was using the master branch, and now tested with the release with tag v1.2 and the error is the same. I have come across this error before with some other code I wrote. You are probably not getting this error because the Arduino is using an older version of the GCC. I am using -std=gnu++2a and some warnings are treated as errors. The error basically complains that the string is truncated because a null terminator copied as a character from the string before the string ends. For myself, I replaced it with memcpy since you are already null terminating the string, but I never loaded the font from a file so I don't know if it works. My board is ESP32-S3 and uses the IDF version v4.4 with Arduino core as a component. Here are the output logs:
Edit: Here is a discussion related to this issue: https://stackoverflow.com/questions/1453876/why-does-strncpy-not-null-terminate I fell like replacing it with memcpy seems safe since you are manually null-terminating the string. But using strncat would be the preferred solution. |
The compilation completed successfully in my esp-idf 4.4 environment. Thank you. |
You add it to the CMakeLists.txt file inside the main folder. Mine is like this:
Be careful that it is not the one in the project folder, but the main folder inside the project folder. https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/cplusplus.html |
I tried in my environment and did not encounter any errors. I don't know if my settings are wrong or if I need to set something else in the IDE. If it is possible, can you provide a project that can reproduce the state? Thank you. |
Looks correct but I don't know what differs from my project to yours. I will make an example and put it on GitHub for you to try. In the meantime, I see that you have some warnings. The problem might be hidden in those warnings. Try adding -Werror flag to treat all warnings as errors so you could see it. |
Here is the minimal project sample I created that replicates the issue on my machine (Ubuntu Linux 22.04 with ESP-IDF v4.4) |
Another issue that comes to my mind, is that you using Eclipse or whatever IDE could be giving additional arguments to the compiler. Thus, suppressing the errors. I say we replace the strncpy with memcpy and call it a day. The code compiles that way and it seems safe to me. The only thing is that I can’t test the function by loading a font file from a file system. Perhaps you could test that. But I believe it will probably work. We just replace it with memcpy and won’t be wasting your time with this issue. I can open a pull request if you’d like, and you can test it. |
Thanks for providing the sample project! |
Thank you for the hint! What I quickly did though was adding OpenFontRender to my target project and trying compiling it. To my surprise, I run out of memory :( Without OpenFontRender
With OpenFontRender
|
@takkaO OpenFontRenderer: Noto_Font_Demo with loading the NotoSans_Bold font
OpenFontRenderer: Noto_Font_Demo without loading the NotoSans_Bold font
Thank you for the support! |
I think you should open a separate issue for that |
I have modified the code based on the sample code you provided. The code is currently uploaded on the Thank you. |
Hello, I confirm it to be working on my end. But I think you should also test it by loading the fonts from the file system. Since my fonts are in the code, it doesn't use that function. |
Hello, OpenFontRender is great, compliments for that!
I am using OpenFontRender together with TFT_eSPI library (2.5.43).
Using Arduino IDE 2.3.2, I can build the Noto_Font_Demo (https://github.com/takkaO/OpenFontRender/tree/master/examples/TFT_eSPI/Noto_Font_Demo) and run it on ESP32 board using a TFT with an ILI9341 controller.
Unfortunately, I cannot compile the same for a Teensy board (tried versions 3.1, 3.6, 4.1).
I get a linker error, please see below (a few warnings first and the error is at the bottom).
I could not figure out what the problem is. Help fixing this is highly appreciated because I would like to use OpenFontRender in a project with a Teensy board.
Note: Without OpenFontRender, I can successfully build and run projects with Teensy 4.1 (1.59.0), TFT_eSPI (2.5.43), and the same TFT display.
Output from Arduino IDE 2.3.2
\arduino\libraries\OpenFontRender\src\sfnt\ttcmap.c:55:3: warning: 'tt_cmap_init' defined but not used [-Wunused-function]
55 | tt_cmap_init( TT_CMap cmap,
\arduino\libraries\OpenFontRender\src\OpenFontRender.cpp: In member function 'uint16_t OpenFontRender::drawHString(const char*, int32_t, int32_t, uint16_t, uint16_t, Align, Drawing, FT_BBox&, FT_Error&)':
\arduino\libraries\OpenFontRender\src\OpenFontRender.cpp:774:75: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'long int'} and 'long unsigned int' [-Wsign-compare]
774 | if (_saved_state.drawn_bg_point.x < (pos.x + (uint32_t)bit->bitmap.width)) {
\arduino\libraries\OpenFontRender\src\OpenFontRender.cpp: In member function 'void OpenFontRender::draw2screen(FT_BitmapGlyph, uint32_t, uint32_t, uint16_t, uint16_t)':
\arduino\libraries\OpenFontRender\src\OpenFontRender.cpp:1431:83: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'long int'} and 'long unsigned int' [-Wsign-compare]
1431 | if (_saved_state.drawn_bg_point.x <= (x + _x)) {
\arduino\libraries\OpenFontRender\src\OpenFontRender.cpp:1462:75: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'long int'} and 'long unsigned int' [-Wsign-compare]
1462 | if (_saved_state.drawn_bg_point.x <= (x + _x)) {
\arduino\libraries\OpenFontRender\src\OpenFontRender.cpp: In member function 'FT_Error OpenFontRender::loadFont(const char*, uint8_t)':
\arduino\libraries\OpenFontRender\src\OpenFontRender.cpp:446:16: warning: 'char* strncpy(char*, const char*, size_t)' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
446 | strncpy(_face_id.filepath, fpath, len);
\arduino\libraries\OpenFontRender\src\OpenFontRender.cpp:443:28: note: length computed here
443 | size_t len = strlen(fpath);
/arduino15/packages/teensy/tools/teensy-compile/11.3.1/arm/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: /arduino15/packages/teensy/tools/teensy-compile/11.3.1/arm/bin/../lib/gcc/arm-none-eabi/11.3.1/thumb/v7e-m+dp/hard\libc.a(libc_a-openr.o): in function `_open_r':
(.text._open_r+0x14): undefined reference to `_open'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
The text was updated successfully, but these errors were encountered: