praydog / REFramework

Scripting platform, modding framework and VR support for all RE Engine games
https://cursey.github.io/reframework-book/
MIT License
2.68k stars 338 forks source link

imgui.input_text boxes deselect, preventing text input #1050

Closed LittleSisterLover closed 2 months ago

LittleSisterLover commented 2 months ago

Describe the bug imgui.input_text deselects seemingly on frame, preventing input completely.

Upload logs and any crash dumps re2_framework_log.txt

Identify the REFramework version First noticed on Nightly842, still present in Nightly869 and Nightly878. Is not present on Nightly802-bugfix.

To Reproduce Steps to reproduce the behavior: Run an REFramework Lua script using the imgui.input_text function within its generated UI, attempt to click the box and observe that it does not stay selected.

Expected behavior Text box should remain selected until clicked outside of it.

Desktop and VR (please complete the following information):

praydog commented 2 months ago

Cannot reproduce. Please provide a sample script. Try removing your other scripts.

LittleSisterLover commented 2 months ago

Here's a simple test script in which the issue occurs: imguitestt.zip

Further testing has shown that this only occurs in Nightly878 if the value passed through the "label" parameter (as defined at https://cursey.github.io/reframework-book/api/imgui.html) is an empty string.

This was not the case in Nightly802-bugfix, wherein any string passed through the "label" parameter would work.

I should also have mentioned originally that this was specifically encountered in Dragon's Dogma 2.

praydog commented 2 months ago

Use imgui.push/pop_id around empty input boxes to fix this. This doesn't seem like a bug, and was likely fixed when ImGui was upgraded to 1.90.1. If anything, it seemed like a bug before that this wasn't happening.

https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-about-the-id-stack-system

Example:

imgui.push_id("My unique Identifier")
local changed, value = imgui.input_text("", display_text)
-- logic
imgui.pop_id()
LittleSisterLover commented 2 months ago

Interesting. I was using push/pop_id for identifiers during loops, but didn't consider it here. If I'm following correctly, the label is used as the identifier for text_input. An empty string leaves it without an one, which causes the behaviour. Pushing/popping an ID then puts one in its place, allowing it to work. There must've been a change in the update to how identifiers are handled that leads to an empty string no longer being a valid identifier.

Regardless, thank you for both looking into this and providing a reference.