Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GWindow:: Multiple Calls to addTimerListener / removeTimerListener cause a buildup of duplicate timers. #1

Open
koopdi opened this issue Mar 6, 2022 · 1 comment

Comments

@koopdi
Copy link

koopdi commented Mar 6, 2022

The following code causes this::animate() to be called 21 times every second.
// testing double timer syndrome

for (int i = 0; i < 10; i++)
{
  win.setTimerListener(1000, [this] { animate(); });
  win.removeTimerListener();
  win.setTimerListener(1000, [this] { animate(); });
  win.removeTimerListener();
}
win.setTimerListener(1000, [this] { animate(); });
@koopdi
Copy link
Author

koopdi commented Mar 6, 2022

Here is a fix that worked in my particular case. With this change, animate() is called exactly 1 time every second.

// gwindow.cpp
void GWindow::removeTimerListener() {
    removeEventListener("timer");

    GThread::runOnQtGuiThread([this]()
    {
        while(!_iqmainwindow->_timerIDs.empty())
        {
            auto it = _iqmainwindow->_timerIDs.begin();
            _iqmainwindow->timerStop((*it));
        }
    }); // runOnQtGuiThread
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant