jvcleave / ofxImGui

Use ImGui in openFrameworks
300 stars 123 forks source link

Assert triggered by negative io.DeltaTime #51

Open hamoid opened 7 years ago

hamoid commented 7 years ago

I realized that if I let the iOS app I'm building run for 10 or 20 minutes, it triggers an assert error on line imgui.cpp:2044 on this line:

IM_ASSERT(g.IO.DeltaTime >= 0.0f);    
// Need a positive DeltaTime (zero is tolerated but will cause some timing issues)

During this time I do not interact with the app. I just let it run. I see the used values are all floats, so they should not overflow in such a short time. What could be the reason?

Maybe a simple solution would be to replace this

    float currentTime = ofGetElapsedTimef();
    if (lastTime > 0.f)
    {
        io.DeltaTime = currentTime - lastTime;
    }
    else
    {
        io.DeltaTime = 1.0f / 60.f;
    }

with this

    float currentTime = ofGetElapsedTimef();
    if (currentTime > lastTime)
    {
        io.DeltaTime = currentTime - lastTime;
    }
    else
    {
        io.DeltaTime = 1.0f / 60.f;
    }

This would avoid negative values, but it does not explain how they happen in the first place.

I'm running my app at 30 fps. Could that be an issue?

hamoid commented 7 years ago

It's also possible that it's unrelated to ofxImGui... Maybe a floating point arithmetic issue?