Is your code inside your event loop? (If not, it should)
Yup, obviously it is.It's not at all obvious as you didn't show it.
The only difference i believe may have ANY impact is that in the prototype i was polling events directly on a renderwindow object, while in this version it's a pointer and window is created via "new" tagAre you polling the events in a different thread (http://www.sfml-dev.org/tutorials/2.3/window-window.php#things-to-know-about-windows)?
also output multiple times when you press a key?
It's not at all obvious as you didn't show it.
Are you polling the events in a different thread?
int main()
{
Program program; //this object contains the sf::Event mEvent and sf::RenderWindow* mWindow object, which is then shared with all other subsystems
program.run();
}
program.run()
{
while (mRunning)
{
mWindow->pollEvent(mEvent);
if (mEvent.type == sf::Event::Closed)
mRunning = false;
mLoadedSoftware->fillPages();
mLoadedSoftware->updatePages();
mLoadedSoftware->drawPages();
}
}
void Software::updatePages()
{
mActiveState->updatePages();
}
There is no event loop here.while (mRunning)
{
mWindow->pollEvent(mEvent);
if (mEvent.type == sf::Event::Closed)
mRunning = false;
mLoadedSoftware->fillPages();
mLoadedSoftware->updatePages();
mLoadedSoftware->drawPages();
}
There is no event loop here.
You are polling once, then processing the entire frame using that one event. This isn't technically incorrect but it's not taking into account if pollEvent() fails. The event is no longer valid as it's still the same event as it was before and you're still processing it as if it's just received a new one. This is why all event processing usually goes within a specific event loop that only processes the event if polling was successful.
sf::Event event;
while (window.pollEvent(event))
hence it worked like a charm. Added a while loop within while(mRunning) and bingo. You, Sir, are a kind genius and a scholar.Also, you might consider creating (or resetting) the event each frame, just before the event polling. That way, the event is - at least - in its default state, rather than its previous state.
However, since an event can't hold "no event has occurred" (and why would it?), you would be processing the event as if the default event has occurred (which, I think would be Closed so if this closes your window immediately, you can see why)