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

Author Topic: [SOLVED] Using SFML with ImGui and the NewFrame issue  (Read 6828 times)

0 Members and 2 Guests are viewing this topic.

synok

  • Newbie
  • *
  • Posts: 18
    • View Profile
[SOLVED] Using SFML with ImGui and the NewFrame issue
« on: September 16, 2019, 02:00:21 am »
Hello!

I have been working a while on something with ImGui in SFML. Everything seems fine so far until one day I am randomly stumbling upon issues with it. Appearantly it is related to ImGui::NewFrame not beeing called properly. I can't remember that I ever had to call it at all. Anyways, I followed the code from the examples here:

https://github.com/eliasdaler/imgui-sfml

As I said, it worked fine before. But now, out of the blue, it asks me if I have called ImGui::NewFrame; which is odd. Since I do not handle the setup of the window everyday, or everytime I work on it, I cannot remember where it would be, also since I optimized a lot of the code.

I have previously added commits that have been working fine and tested onto Github, but now when I pull one of the commits from there to try out, I face the exact same error. Everything compiles fine, but I stumble on the assert errors when I run it. Debugging simply leads me to a comment that says "Did you forgot to add ImGui::NewFrame;?"

No I didnt forget it, I just never really had to.

Anyone having any idea, it would be great. I will try different things here to come up with a solution.
« Last Edit: September 16, 2019, 11:15:56 pm by synok »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Using SFML with ImGui and the NewFrame issue
« Reply #1 on: September 16, 2019, 10:42:59 am »
Are you using the example code exactly? If not, can you provide your code?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Using SFML with ImGui and the NewFrame issue
« Reply #2 on: September 16, 2019, 11:23:02 am »
Here are my two guesses:
1) You use ImGui older than v1.68 (and recent ImGui-SFML require it)
2) Your game loop differs from what ImGui-SFML expect (some things changed in recent versions, as far as I remember). It's especially important to call ImGui::SFML::Update update function before calling any ImGui functions in the frame.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

synok

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Using SFML with ImGui and the NewFrame issue
« Reply #3 on: September 16, 2019, 04:53:40 pm »
Thanks for your replies! The code is structured up in different classes, but I guess this is the part you are wondering about https://pastebin.com/rS7nuish

The commented ImGui::NewFrame() is where I suspected it to be. But repositioning everywhere in the code it did not help. As I said, before I did not really need it for whatever reason, and I have working compiles of the code to prove it. Not sure why it seems to be such a big issue now.

Edit: Here is where I use ImGui https://pastebin.com/cvHJmzVy
« Last Edit: September 16, 2019, 05:04:58 pm by synok »

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Using SFML with ImGui and the NewFrame issue
« Reply #4 on: September 16, 2019, 05:53:00 pm »
Where is LogonWindow called?
You need to call ImGui::SFML::Update before calling it.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Using SFML with ImGui and the NewFrame issue
« Reply #5 on: September 16, 2019, 05:55:01 pm »
void updateWindow(_GAME *pGame)
{
   
    while (window.isOpen()) {
        sf::Event event;
       
        while (window.pollEvent(event)) {
            // Process ImGui along with the SFML event
           
            ImGui::SFML::ProcessEvent(event);
           
            if (event.type == sf::Event::Closed) {
                window.close();
            }
            // ImGui::EndFrame(); ????? <- shouldn't be called!
        }

        ImGui::SFML::Update(window, dt);

        ...
        // call LogonWindow here
 
        window.clear(sf::Color::Black);
 
        //window.clear(sf::Color::Black);
       
        ImGui::SFML::Render(window);
        window.display();
       
    }
 
    ImGui::SFML::Shutdown();
}
 
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

synok

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Using SFML with ImGui and the NewFrame issue
« Reply #6 on: September 16, 2019, 06:28:23 pm »
void updateWindow(_GAME *pGame)
{
   
    while (window.isOpen()) {
        sf::Event event;
       
        while (window.pollEvent(event)) {
            // Process ImGui along with the SFML event
           
            ImGui::SFML::ProcessEvent(event);
           
            if (event.type == sf::Event::Closed) {
                window.close();
            }
            // ImGui::EndFrame(); ????? <- shouldn't be called!
        }

        ImGui::SFML::Update(window, dt);

        ...
        // call LogonWindow here
 
        window.clear(sf::Color::Black);
 
        //window.clear(sf::Color::Black);
       
        ImGui::SFML::Render(window);
        window.display();
       
    }
 
    ImGui::SFML::Shutdown();
}
 

Thank you! I noticed I messed up ImGui::SFML::Update. Everything works fine now :)

Solution: If someone stumbles upon the same issue in the future, please refer to Elias Daler's code snippet above.
« Last Edit: September 16, 2019, 11:17:08 pm by synok »

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Using SFML with ImGui and the NewFrame issue
« Reply #7 on: September 16, 2019, 08:35:45 pm »
You're welcome. :)
Please add "[SOLVED]" to threads title.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler