Open J-Cake opened 2 years ago
Try and null terminate your strings. This worked for me implementing a renderer in GDI
void r_draw_text(const char* text, mu_Vec2 pos, mu_Color color) {
char buff[1024] = { 0 };
strcat(buff, text);
strcat(buff, "\0");
SelectObject(Memhdc, hFont);
SetBkMode(Memhdc, TRANSPARENT);
SetTextColor(Memhdc, RGB(color.r, color.g, color.b));
ExtTextOutA(Memhdc, pos.x, pos.y, ETO_OPAQUE, NULL, (LPCSTR)buff, sizeof(text), NULL);
}
or since you are using C++ try a std::string and somestring.c_str() to retrieve the char*
I think it is indeed reading into the next byte and not terminating properly, I think this might how GDI (and maybe cairo?) are handling string termination.
aand the fix
I haven't had a chance to test this yet, but something tells me that'll do it
I'm playing around with the demo program, and am noticing that the text rendering function receives a corrupt copy of the text to print. I've also noticed that the source it receives each time is different, meaning it's being corrupted along the way. It's received correctly in the
text_width
function, but I can't find where it could possibly become changed.In short, my code is this:
I can't seem to find the source of the issue. My guess was some sort of memory overwriting, but I removed all memory management calls, and still got the same result.
Some details: