Fix segfault on some systems when using BrowserDialog during a program run.

Remove old debugging print code.
This commit is contained in:
Stephen Anthony 2021-10-24 13:57:40 -02:30
parent 79da2e1d8a
commit c3fa1890d5
6 changed files with 30 additions and 14 deletions

View File

@ -71,8 +71,6 @@ FBBackendSDL2::~FBBackendSDL2()
myWindow = nullptr;
}
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER);
cerr << "~FBBackendSDL2()" << endl;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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;
}

View File

@ -68,7 +68,6 @@ FrameBuffer::FrameBuffer(OSystem& osystem)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBuffer::~FrameBuffer()
{
cerr << "~FrameBuffer()\n";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -911,10 +910,7 @@ shared_ptr<FBSurface> FrameBuffer::allocateSurface(
void FrameBuffer::deallocateSurface(shared_ptr<FBSurface> surface)
{
if(surface)
{
cerr << "deallocateSurface: " << surface << endl;
mySurfaceList.remove(surface);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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<BrowserDialog> ourBrowser{nullptr};
if(ourBrowser == nullptr
|| ourBrowser->getWidth() != int(w) || ourBrowser->getHeight() != int(h))
ourBrowser = make_unique<BrowserDialog>(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> BrowserDialog::ourBrowser;

View File

@ -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<BrowserDialog> ourBrowser;
private:
// Following constructors and assignment operators not supported
BrowserDialog() = delete;