diff --git a/src/common/FBBackendSDL2.cxx b/src/common/FBBackendSDL2.cxx index e9cdab169..a2af7eee5 100644 --- a/src/common/FBBackendSDL2.cxx +++ b/src/common/FBBackendSDL2.cxx @@ -71,8 +71,6 @@ FBBackendSDL2::~FBBackendSDL2() myWindow = nullptr; } SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER); - -cerr << "~FBBackendSDL2()" << endl; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/FBSurfaceSDL2.cxx b/src/common/FBSurfaceSDL2.cxx index 15923a099..a2b8d0166 100644 --- a/src/common/FBSurfaceSDL2.cxx +++ b/src/common/FBSurfaceSDL2.cxx @@ -40,8 +40,6 @@ namespace { } } -static int REF_COUNT = 0; - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FBSurfaceSDL2::FBSurfaceSDL2(FBBackendSDL2& backend, uInt32 width, uInt32 height, @@ -50,7 +48,6 @@ FBSurfaceSDL2::FBSurfaceSDL2(FBBackendSDL2& backend, : myBackend{backend}, myInterpolationMode{inter} { -REF_COUNT++; createSurface(width, height, staticData); } @@ -61,8 +58,6 @@ FBSurfaceSDL2::~FBSurfaceSDL2() if(mySurface) { -REF_COUNT--; -cerr << " ~FBSurfaceSDL2(): " << this << " " << REF_COUNT << endl; SDL_FreeSurface(mySurface); mySurface = nullptr; } diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index 917ed5c66..68af5a9b8 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -68,7 +68,6 @@ FrameBuffer::FrameBuffer(OSystem& osystem) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FrameBuffer::~FrameBuffer() { -cerr << "~FrameBuffer()\n"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -911,10 +910,7 @@ shared_ptr FrameBuffer::allocateSurface( void FrameBuffer::deallocateSurface(shared_ptr surface) { if(surface) - { - cerr << "deallocateSurface: " << surface << endl; mySurfaceList.remove(surface); - } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 6128844a8..ecbd1de62 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -31,6 +31,7 @@ #include "Debugger.hxx" #endif #ifdef GUI_SUPPORT + #include "BrowserDialog.hxx" #include "OptionsMenu.hxx" #include "CommandMenu.hxx" #include "HighScoresMenu.hxx" @@ -112,7 +113,13 @@ OSystem::OSystem() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OSystem::~OSystem() { -cerr << "~OSystem()\n"; +#ifdef GUI_SUPPORT + // BrowserDialog is a special dialog that is statically allocated + // So we need to make sure that it is destroyed in the normal d'tor chain; + // not at the very end of program exit, when some objects it requires + // have already been destroyed + BrowserDialog::hide(); +#endif } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/BrowserDialog.cxx b/src/gui/BrowserDialog.cxx index 8a0f73019..a60c4cb55 100644 --- a/src/gui/BrowserDialog.cxx +++ b/src/gui/BrowserDialog.cxx @@ -115,6 +115,7 @@ BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// static void BrowserDialog::show(GuiObject* parent, const GUI::Font& font, const string& title, const string& startpath, BrowserDialog::Mode mode, @@ -127,8 +128,6 @@ void BrowserDialog::show(GuiObject* parent, const GUI::Font& font, if(w > uInt32(font.getMaxCharWidth() * 80)) w = font.getMaxCharWidth() * 80; - static unique_ptr ourBrowser{nullptr}; - if(ourBrowser == nullptr || ourBrowser->getWidth() != int(w) || ourBrowser->getHeight() != int(h)) ourBrowser = make_unique(parent, font, w, h); @@ -138,6 +137,7 @@ void BrowserDialog::show(GuiObject* parent, const GUI::Font& font, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// static void BrowserDialog::show(GuiObject* parent, const string& title, const string& startpath, BrowserDialog::Mode mode, @@ -148,6 +148,13 @@ void BrowserDialog::show(GuiObject* parent, mode, command, namefilter); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// static +void BrowserDialog::hide() +{ + ourBrowser.reset(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void BrowserDialog::show(const string& startpath, BrowserDialog::Mode mode, @@ -326,3 +333,6 @@ void BrowserDialog::updateUI(bool fileSelected) if(fileSelected && !_fileList->selected().isDirectory()) _selected->setText(_fileList->getSelectedString()); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +unique_ptr BrowserDialog::ourBrowser; diff --git a/src/gui/BrowserDialog.hxx b/src/gui/BrowserDialog.hxx index 4614c5e46..62a3dfed1 100644 --- a/src/gui/BrowserDialog.hxx +++ b/src/gui/BrowserDialog.hxx @@ -85,6 +85,14 @@ class BrowserDialog : public Dialog const FilesystemNode::NameFilter& namefilter = { [](const FilesystemNode&) { return true; } }); + /** + Since the show methods allocate a static BrowserDialog, at some + point we need to manually de-allocate it. This method must be + called from one of the lowest-level destructors to do that. + Currently this is called from the OSystem destructor. + */ + static void hide(); + private: /** Place the browser window onscreen, using the given attributes */ void show(const string& startpath, @@ -119,6 +127,8 @@ class BrowserDialog : public Dialog BrowserDialog::Mode _mode{Mode::Directories}; + static unique_ptr ourBrowser; + private: // Following constructors and assignment operators not supported BrowserDialog() = delete;