Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]ImGui::InputText() spamming the first character typed into the text box.  (Read 4216 times)

0 Members and 1 Guest are viewing this topic.

Riser

  • Newbie
  • *
  • Posts: 33
    • View Profile
So I posted this on the ImGui issues tracker but they closed it and told me to post it on the SFML-ImGui issues tracker, except that one is inactive so this is my last hope to get an answer...

I'm using ImGui with SFML and I'm trying to make a text-box that stores a file path.



I followed what this post did: (https://github.com/ocornut/imgui/issues/2487#issuecomment-482474783) but what keeps happening is that the textbox will start repeating the first character typed into it until the entire buffer is filled with the same repeated character, example:





I also tried moving the buffer inside the loop and got the same result, what am I doing wrong?
« Last Edit: January 29, 2022, 04:38:26 pm by Riser »

kojack

  • Sr. Member
  • ****
  • Posts: 310
  • C++/C# game dev teacher.
    • View Profile
Re: ImGui::InputText() spamming the first character typed into the text box.
« Reply #1 on: January 29, 2022, 12:01:07 pm »
How are you handling passing input to Imgui?
In the ImGui SFML addon I use, I need to do:
ImGui::SFML::ProcessEvent(event);
in the SFML event loop.

Riser

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: ImGui::InputText() spamming the first character typed into the text box.
« Reply #2 on: January 29, 2022, 12:45:44 pm »
Yeah I already have that line included in another file along with the rest of the SFML window setup:

#include "Window.h"

sf::RenderWindow w(sf::VideoMode(1000, 700), "Window");
sf::Event e;
window_methods mw;

void window_methods::close_window() {
        ImGui::SFML::ProcessEvent(e);
        while (w.pollEvent(e)) {
                switch (e.type) {
                case sf::Event::Closed:
                        w.close();
                        break;
                }
        }
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: ImGui::InputText() spamming the first character typed into the text box.
« Reply #3 on: January 29, 2022, 01:37:27 pm »
The ProcessEvent call needs to be inside the event loop, otherwise you'll just get random behavior, as you're using some old union sf::Event state.

See the example here: https://github.com/eliasdaler/imgui-sfml#using-imgui-sfml-in-your-code

Also not sure why you'd think the issue tracker of ImGui-SFML is inactive... ???
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Riser

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: ImGui::InputText() spamming the first character typed into the text box.
« Reply #4 on: January 29, 2022, 04:37:59 pm »
Yup, moving everything back to the main.cpp file fixed the problem, and also fixed another problem I was having where I couldn't interact with the ImGui widgets if I clicked off the SFML window.

So yeah, moving those 5 lines to a separate file to have less code in the main.cpp files defiantly wasn't worth it.

As for the ImGui-SFML issue tracker, well, there are barely any posts on there, and all of the posts made during 2021 either have one or no replies so it seemed pretty dead to me.

kojack

  • Sr. Member
  • ****
  • Posts: 310
  • C++/C# game dev teacher.
    • View Profile
It's not that the code was in a seperate file as such, it's that:
ImGui::SFML::ProcessEvent(e);
while (w.pollEvent(e)) {
should have been:
while (w.pollEvent(e)) {
ImGui::SFML::ProcessEvent(e);
 
You were passing an event to Imgui before reading the event (pollEvent), so it just contained a leftover of the last event from the previous pass of the while loop. (So if a key event came through, every frame after that would see the same key event repeat until a different event wrote over it)

Riser

  • Newbie
  • *
  • Posts: 33
    • View Profile
Oh, I did notice that mistake and fix it while moving everything over to the main file, didn't realize it was the actual source of the problem, I guess I'll go move the code back if I feel like it's worth it.

Oh well, the more you learn, thanks!
« Last Edit: January 29, 2022, 08:02:38 pm by Riser »

 

anything