enkisoftware / imgui_markdown

Markdown for Dear ImGui
zlib License
1.03k stars 69 forks source link

Infinite loop when widget doesn't have enough horizontal space to fit a word. #4

Closed bkaradzic closed 5 years ago

bkaradzic commented 5 years ago

There is bug here: https://github.com/juliettef/imgui_markdown/blob/d1726b1385f5790182892e41d4d8001a91fa0e04/imgui_markdown.h#L201

When widthLeft is too small to fit whole word endPrevLine doesn't advance and it causes infinite loop.

My workaround was:

if (text == endPrevLine) {
    endPrevLine++;
}

Other minor issues:

This: https://github.com/juliettef/imgui_markdown/blob/d1726b1385f5790182892e41d4d8001a91fa0e04/imgui_markdown.h#L155

Should be (fixes clang error): HeadingFormat headingFormats[ NUMHEADINGS ] = { { NULL, true }, { NULL, true }, { NULL, true } };

Also I would suggest to create .h file that contains only definitions users should use. I did this inside bgfx: https://github.com/bkaradzic/bgfx/blob/master/3rdparty/dear-imgui/widgets/markdown.h

Sorry for not creating PR...

juliettef commented 5 years ago

Thanks for reporting those, fixing them asap!

dougbinks commented 5 years ago

Thanks @bkaradzic I've opened a question issue on this to get feedback.