ImFont::RenderText() issue #6132

Closed
opened 2023-01-31 11:23:30 +00:00 by tksuoran · 7 comments
tksuoran commented 2023-01-31 11:23:30 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version: 1.89.3
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: custom / erhe
Compiler: VS 2022 17.4.4
Operating System: Windows 10

My Issue/Question:

I encountered IM_ASSERT_PARANOID() failure in ImDrawList::PrimReserve() due to negative arguments being passed from ImFont::RenderText(). This was caused by s pointing to one past text_end. text_begin pointed to Material and text_end looked valid. I am not sure exactly what path resulted in s pointing to text_end + 1. I have not been able to repro, so this may be some corner case that is not easy to hit.

**Version/Branch of Dear ImGui:** Version: 1.89.3 Branch: docking **Back-end/Renderer/Compiler/OS** Back-ends: custom / erhe Compiler: VS 2022 17.4.4 Operating System: Windows 10 **My Issue/Question:** I encountered `IM_ASSERT_PARANOID()` failure in `ImDrawList::PrimReserve()` due to negative arguments being passed from `ImFont::RenderText()`. This was caused by `s` pointing to one past `text_end`. `text_begin` pointed to `Material` and `text_end` looked valid. I am not sure exactly what path resulted in `s` pointing to `text_end + 1`. I have not been able to repro, so this may be some corner case that is not easy to hit.
ocornut commented 2023-01-31 11:29:12 +00:00 (Migrated from github.com)

Intuitively I imagine ccf94e2e6e could be at fault because it is a very-recent change that align with some of the elements of that issues. If you repro more details would be useful.

Or: was text-wrapping active? that's to rule out whole chunks of code including bits that have changed.

Intuitively I imagine ccf94e2e6e2c3eb889e7ef26c0a38062330425d6 could be at fault because it is a very-recent change that align with some of the elements of that issues. If you repro more details would be useful. Or: was text-wrapping active? that's to rule out whole chunks of code including bits that have changed.
tksuoran commented 2023-01-31 11:32:06 +00:00 (Migrated from github.com)

I can now repro. This happens with TreeNodeEx() that gets completely clipped / scrolled so that it is not visible, with flags ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick |ImGuiTreeNodeFlags_SpanFullWidth, word_wrap_enabled == false.

Perhaps // Fast-forward to first visible line is at fault, when there is no line at all that is visible? That code section has s = line_end + 1.

I can now repro. This happens with `TreeNodeEx()` that gets completely clipped / scrolled so that it is not visible, with flags `ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick |ImGuiTreeNodeFlags_SpanFullWidth`, `word_wrap_enabled == false`. Perhaps `// Fast-forward to first visible line` is at fault, when there is no line at all that is visible? That code section has `s = line_end + 1`.
tksuoran commented 2023-01-31 11:34:26 +00:00 (Migrated from github.com)

Indeed the code path in my previous comment is executed and that is how s gets text_end + 1 value.

Indeed the code path in my previous comment is executed and that is how `s` gets `text_end + 1` value.
tksuoran commented 2023-01-31 11:36:33 +00:00 (Migrated from github.com)
+		this	0x000001e03dc44f80 {IndexAdvanceX={Size=256 Capacity=256 Data=0x000001e0313a0bf0 {6.00000000} } FallbackAdvanceX=...}	const ImFont *
+		clip_rect	{x=1.00000000 y=699.000000 z=168.000000 ...}	const ImVec4 &
		col	2634022911	unsigned int
		col_untinted	3435973836	const unsigned int
		cpu_fine_clip	false	bool
+		draw_list	0x000001e0046c8e78 {CmdBuffer={Size=1 Capacity=8 Data=0x000001e01ef86e30 {ClipRect={x=1.00000000 y=699.000000 ...} ...} } ...}	ImDrawList *
		idx_count_max	-6	const int
		idx_expected_size	15	const int
+		idx_write	0xcccccccccccccccc {???}	unsigned short *
		line_height	17.0000000	const float
+		pos	{x=44.0000000 y=681.000000 }	const ImVec2 &
+		s	0x00007ff67604a8b1 ""	const char *
		scale	1.00000000	const float
		size	17.0000000	float
		start_x	44.0000000	const float
+		text_begin	0x00007ff67604a8a8 "Material"	const char *
+		text_end	0x00007ff67604a8b0 ""	const char *
		vtx_count_max	-4	const int
		vtx_index	3435973836	unsigned int
+		vtx_write	0xcccccccccccccccc {pos={x=??? y=??? } uv={x=??? y=??? } col=??? }	ImDrawVert *
		word_wrap_enabled	false	const bool
+		word_wrap_eol	0xcccccccccccccccc <Error reading characters of string.>	const char *
		wrap_width	0.00000000	float
		x	44.0000000	float
		y	698.000000	float
``` + this 0x000001e03dc44f80 {IndexAdvanceX={Size=256 Capacity=256 Data=0x000001e0313a0bf0 {6.00000000} } FallbackAdvanceX=...} const ImFont * + clip_rect {x=1.00000000 y=699.000000 z=168.000000 ...} const ImVec4 & col 2634022911 unsigned int col_untinted 3435973836 const unsigned int cpu_fine_clip false bool + draw_list 0x000001e0046c8e78 {CmdBuffer={Size=1 Capacity=8 Data=0x000001e01ef86e30 {ClipRect={x=1.00000000 y=699.000000 ...} ...} } ...} ImDrawList * idx_count_max -6 const int idx_expected_size 15 const int + idx_write 0xcccccccccccccccc {???} unsigned short * line_height 17.0000000 const float + pos {x=44.0000000 y=681.000000 } const ImVec2 & + s 0x00007ff67604a8b1 "" const char * scale 1.00000000 const float size 17.0000000 float start_x 44.0000000 const float + text_begin 0x00007ff67604a8a8 "Material" const char * + text_end 0x00007ff67604a8b0 "" const char * vtx_count_max -4 const int vtx_index 3435973836 unsigned int + vtx_write 0xcccccccccccccccc {pos={x=??? y=??? } uv={x=??? y=??? } col=??? } ImDrawVert * word_wrap_enabled false const bool + word_wrap_eol 0xcccccccccccccccc <Error reading characters of string.> const char * wrap_width 0.00000000 float x 44.0000000 float y 698.000000 float ```
ocornut commented 2023-01-31 11:36:34 +00:00 (Migrated from github.com)

Thank you, I can repro with #define IMGUI_DEBUG_PARANOID. Now going to lunch but going to look into this afterwards.

Thank you, I can repro with `#define IMGUI_DEBUG_PARANOID`. Now going to lunch but going to look into this afterwards.
ocornut commented 2023-01-31 11:40:09 +00:00 (Migrated from github.com)

Broken by 3482d4ec (#5720, #5919)

Broken by 3482d4ec (#5720, #5919)
ocornut commented 2023-01-31 13:44:08 +00:00 (Migrated from github.com)

Pushed fix 867bdbe

Interestingly, it would trigger with IMGUI_DEBUG_PARANOID defined, but without it would work as the count is cancelled at the end of the function (but it would run some extra code unnecessarily).

Thank you!

Pushed fix 867bdbe Interestingly, it would trigger with `IMGUI_DEBUG_PARANOID` defined, but without it would work as the count is cancelled at the end of the function (but it would run some extra code unnecessarily). Thank you!
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#6132
No description provided.