c++ - TTF_RenderUTF8_Shaded invalid read -


when using hans kendrick font sdl2_ttf;

#include <stdio.h> #include <sdl2/sdl.h> #include <sdl2/sdl_ttf.h>  // shortened demo purposes int main () {     if (sdl_init(sdl_init_video) != 0) { return 1; }     if (ttf_init() == -1) { return 1; }      ttf_font *font = ttf_openfont("font.ttf", 28);      if (font == null) { return 1; }      sdl_color blank = {0, 0, 0, 0};     sdl_color colour = {0, 0, 0, 0};      ttf_renderutf8_shaded(font, "y", colour, blank); } 

valgrind reports error;

==18109== invalid read of size 1 ==18109==    @ 0x535812c: ttf_renderutf8_shaded (in /usr/lib/libsdl2_ttf-2.0.so.0.10.2) ==18109==    0x40080b: main (in /home/joshua/fontbug/test) ==18109==  address 0xd9aaf4f 1 bytes before block of size 560 alloc'd ==18109==    @ 0x4c28730: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==18109==    0x4ed91fb: ??? (in /usr/lib/libsdl2-2.0.so.0.2.1) ==18109==    0x5357f00: ttf_renderutf8_shaded (in /usr/lib/libsdl2_ttf-2.0.so.0.10.2) ==18109==    0x40080b: main (in /home/joshua/fontbug/test) 

and systems crash. depends on characters (strings space @ front have never had problem) , possibly font size.

using dejavu not have problem.

what causing this, , how preventable?


to build:

g++ -o test main.cpp $(sdl2-config --cflags --libs) -lsdl2_ttf 

i think (= not 100% sure) must have renderer before trying render . why don't try use sdl_createwindowandrenderer before using ttf_renderutf8_shaded ?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -