2

I currently have a problem with SFML closing. All my project is running on MacBook Pro (15-inch, 2018) Catalina 10.15.3.

My project is to build an Arcade system in C++. We process with a Core system which can interact with a dynamic graphic library and a dynamic game library (both build by myself in C++).

I have 1 ncurses lib, 1 SFML lib and one SDL2 lib. The main task is, we can switch the graphic/game lib at running time (everything work great). All libs is open and close with dl library (error throwed).

project schema

project schema

But here is my problem: when I switch from SFML to Ncurses, my SFML window dosen't close (not responding) but when I switch to SDL2, it close correctly and instantly.

/* this->_window declaration is sf::RenderWindow _window; */

/* Method called in main loop (equal to a window.isOpen() for generic code) */
bool GraphicSfml::shouldExit() const
{
    return (this->_exit);
}

/* Method called when special event is catch */
void GraphicSfml::exit()
{
    this->_window.close();
    this->_exit = !this->_window.isOpen();
}

When I catch an event corresponding to a graphic lib switch I exit and destroy the old graphic lib before the load of the new one.

/* The actual main loop in my Core class, declarations are:
       std::shared_ptr<IGraphics> _lib;
       std::shared_ptr<IGameLogic> _game;
       Arcade::Event e; my custom event
       Arcade::Event::EventTypeEnum::EXIT;
       Arcade::Event::EventTypeEnum::NEXTL; next graph lib
       std::vector<Arcade::AGraphicElement *> elems; graphical element containing to draw 
                                                     (like sf::Rect, sf::Text, ...)
*/
while (!this->_lib->shouldExit()) {
    this->_lib->doClear();
    while (this->_lib->pollEvent(e)) {
        switch (e.getType()) {
            case EXIT:
            this->_lib->exit();
            break;
            case NEXTL:
            switchLibGraph(true);
            default:
            this->_game->onEvent(e);
            break;
        }
        e = Event(UNKNOW);
    }
    elems = this->_game->updateGame();
    displayGameElements(elems);
    this->_lib->doRefresh();
}

Tried things who didn't close:

  • Waiting all event to empty event queue of SFML
  • Change my boolean with the window.isOpen() of SFML with changes needed in my code

Thank you, I hope you have the solution ! ;)

Laurel
  • 5,965
  • 14
  • 31
  • 57
Wazted
  • 101
  • 1
  • 9

0 Answers0