Fixed segfault issues when the SDL video mode cannot be created. This

doesn't happen very often (which is why I didn't notice it before), but
at least now if it *does*  happen, an error message will be printed
instead of just segfaulting.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1536 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2008-05-30 19:07:55 +00:00
parent 66ab71a5c6
commit 340ee7d167
18 changed files with 98 additions and 67 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Snapshot.cxx,v 1.21 2008-05-20 14:35:50 stephena Exp $
// $Id: Snapshot.cxx,v 1.22 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#include <zlib.h>
@ -47,7 +47,7 @@ void Snapshot::savePNG(FrameBuffer& framebuffer, const Properties& props,
out.open(filename.c_str(), ios_base::binary);
if(!out.is_open())
throw "Error: Couldn't create snapshot file";
throw "ERROR: Couldn't create snapshot file";
// PNG file header
uInt8 header[8] = { 137, 80, 78, 71, 13, 10, 26, 10 };
@ -86,7 +86,7 @@ void Snapshot::savePNG(FrameBuffer& framebuffer, const Properties& props,
compmem = new uInt8[compmemsize];
if(compmem == NULL ||
(compress(compmem, &compmemsize, buffer, height * (width * 3 + 1)) != Z_OK))
throw "Error: Couldn't compress PNG";
throw "ERROR: Couldn't compress PNG";
// Write the compressed framebuffer data
writePNGChunk(out, "IDAT", compmem, compmemsize);

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: mainSDL.cxx,v 1.80 2008-02-06 13:45:19 stephena Exp $
// $Id: mainSDL.cxx,v 1.81 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#include <SDL.h>
@ -123,7 +123,7 @@ int main(int argc, char* argv[])
if(argc > 1 && FilesystemNode::fileExists(romfile))
cout << theOSystem->getROMInfo(romfile);
else
cout << "Error: ROM doesn't exist" << endl;
cout << "ERROR: ROM doesn't exist" << endl;
Cleanup();
return 0;
@ -154,7 +154,13 @@ int main(int argc, char* argv[])
// If not, use the built-in ROM launcher. In this case, we enter 'launcher'
// mode and let the main event loop take care of opening a new console/ROM.
if(argc == 1 || romfile == "" || !FilesystemNode::fileExists(romfile))
theOSystem->createLauncher();
{
if(!theOSystem->createLauncher())
{
Cleanup();
return 0;
}
}
else if(theOSystem->createConsole(romfile))
{
if(theOSystem->settings().getBool("takesnapshot"))

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Debugger.cxx,v 1.127 2008-05-18 20:04:30 stephena Exp $
// $Id: Debugger.cxx,v 1.128 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#include "bspf.hxx"
@ -166,12 +166,12 @@ void Debugger::initialize()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Debugger::initializeVideo()
bool Debugger::initializeVideo()
{
GUI::Rect r = getDialogBounds();
string title = string("Stella ") + STELLA_VERSION + ": Debugger mode";
myOSystem->frameBuffer().initialize(title, r.width(), r.height());
return myOSystem->frameBuffer().initialize(title, r.width(), r.height());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Debugger.hxx,v 1.94 2008-05-14 18:04:57 stephena Exp $
// $Id: Debugger.hxx,v 1.95 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#ifndef DEBUGGER_HXX
@ -70,7 +70,7 @@ typedef uInt16 (Debugger::*DEBUGGER_WORD_METHOD)();
for all debugging operations in Stella (parser, 6502 debugger, etc).
@author Stephen Anthony
@version $Id: Debugger.hxx,v 1.94 2008-05-14 18:04:57 stephena Exp $
@version $Id: Debugger.hxx,v 1.95 2008-05-30 19:07:55 stephena Exp $
*/
class Debugger : public DialogContainer
{
@ -103,7 +103,7 @@ class Debugger : public DialogContainer
/**
Initialize the video subsystem wrt this class.
*/
void initializeVideo();
bool initializeVideo();
/**
Inform this object of a console change.

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Console.cxx,v 1.147 2008-05-21 21:36:18 stephena Exp $
// $Id: Console.cxx,v 1.148 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#include <cassert>
@ -426,15 +426,15 @@ void Console::setProperties(const Properties& props)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Console::initializeVideo(bool full)
bool Console::initializeVideo(bool full)
{
if(full)
{
string title = string("Stella ") + STELLA_VERSION +
": \"" + myProperties.get(Cartridge_Name) + "\"";
myOSystem->frameBuffer().initialize(title,
myMediaSource->width() << 1,
myMediaSource->height());
if(!myOSystem->frameBuffer().initialize(title,
myMediaSource->width() << 1, myMediaSource->height()))
return false;
myOSystem->frameBuffer().showFrameStats(
myOSystem->settings().getBool("stats"));
@ -456,6 +456,8 @@ void Console::initializeVideo(bool full)
// Make sure auto-frame calculation is only enabled when necessary
myMediaSource->enableAutoFrame(framerate <= 0);
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Console.hxx,v 1.68 2008-05-21 14:01:29 stephena Exp $
// $Id: Console.hxx,v 1.69 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#ifndef CONSOLE_HXX
@ -39,7 +39,7 @@ class System;
This class represents the entire game console.
@author Bradford W. Mott
@version $Id: Console.hxx,v 1.68 2008-05-21 14:01:29 stephena Exp $
@version $Id: Console.hxx,v 1.69 2008-05-30 19:07:55 stephena Exp $
*/
class Console : public Serializable
{
@ -197,8 +197,10 @@ class Console : public Serializable
@param full Whether we want a full initialization,
or only reset certain attributes.
@return False on any errors, else true
*/
void initializeVideo(bool full = true);
bool initializeVideo(bool full = true);
/**
Initialize the audio subsystem wrt this class.

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Control.cxx,v 1.12 2008-05-12 22:40:23 stephena Exp $
// $Id: Control.cxx,v 1.13 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#include <cassert>
@ -133,7 +133,7 @@ bool Controller::save(Serializer& out) const
}
catch(...)
{
cerr << "Error: Controller::save() exception\n";
cerr << "ERROR: Controller::save() exception\n";
return false;
}
return true;
@ -157,7 +157,7 @@ bool Controller::load(Deserializer& in)
}
catch(...)
{
cerr << "Error: Controller::load() exception\n";
cerr << "ERROR: Controller::load() exception\n";
return false;
}
return true;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: EventHandler.cxx,v 1.224 2008-05-20 13:42:50 stephena Exp $
// $Id: EventHandler.cxx,v 1.225 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#include <sstream>
@ -1918,10 +1918,6 @@ void EventHandler::setEventState(State state)
case S_EMULATE:
myOverlay = NULL;
myOSystem->sound().mute(false);
// Controller types only make sense in Emulate mode
myController[0] = myOSystem->console().controller(Controller::Left).type();
myController[1] = myOSystem->console().controller(Controller::Right).type();
break;
case S_PAUSE:

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: EventHandler.hxx,v 1.110 2008-03-30 15:01:38 stephena Exp $
// $Id: EventHandler.hxx,v 1.111 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#ifndef EVENTHANDLER_HXX
@ -61,7 +61,7 @@ enum EventMode {
mapping can take place.
@author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.110 2008-03-30 15:01:38 stephena Exp $
@version $Id: EventHandler.hxx,v 1.111 2008-05-30 19:07:55 stephena Exp $
*/
class EventHandler
{
@ -500,9 +500,6 @@ class EventHandler
// Indicates which paddle the mouse currently emulates
Int8 myPaddleMode;
// Type of device on each controller port (based on ROM properties)
Controller::Type myController[2];
// Holds static strings for the remap menu (emulation and menu events)
static ActionList ourEmulActionList[kEmulActionListSize];
static ActionList ourMenuActionList[kMenuActionListSize];

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBuffer.cxx,v 1.131 2008-05-21 21:01:40 stephena Exp $
// $Id: FrameBuffer.cxx,v 1.132 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#include <sstream>
@ -56,14 +56,18 @@ FrameBuffer::~FrameBuffer(void)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::initialize(const string& title, uInt32 width, uInt32 height)
bool FrameBuffer::initialize(const string& title, uInt32 width, uInt32 height)
{
// Now (re)initialize the SDL video system
// These things only have to be done one per FrameBuffer creation
if(SDL_WasInit(SDL_INIT_VIDEO) == 0)
{
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
return;
{
cerr << "ERROR: Couldn't initialize SDL: " << SDL_GetError() << endl;
return false;
}
}
myInitializedCount++;
myBaseDim.x = myBaseDim.y = 0;
@ -86,7 +90,11 @@ void FrameBuffer::initialize(const string& title, uInt32 width, uInt32 height)
// Initialize video subsystem
VideoMode mode = getSavedVidMode();
initSubsystem(mode);
if(!initSubsystem(mode))
{
cerr << "ERROR: Couldn't initialize video subsystem" << endl;
return false;
}
// And refresh the display
myOSystem->eventHandler().refreshDisplay();
@ -102,6 +110,8 @@ void FrameBuffer::initialize(const string& title, uInt32 width, uInt32 height)
// but only on the first initialization
if(myInitializedCount == 1 && myOSystem->settings().getBool("showinfo"))
cout << about() << endl;
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBuffer.hxx,v 1.95 2008-05-20 13:42:50 stephena Exp $
// $Id: FrameBuffer.hxx,v 1.96 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#ifndef FRAMEBUFFER_HXX
@ -101,7 +101,7 @@ enum {
All GUI elements (ala ScummVM) are drawn here as well.
@author Stephen Anthony
@version $Id: FrameBuffer.hxx,v 1.95 2008-05-20 13:42:50 stephena Exp $
@version $Id: FrameBuffer.hxx,v 1.96 2008-05-30 19:07:55 stephena Exp $
*/
class FrameBuffer
{
@ -125,8 +125,10 @@ class FrameBuffer
@param title The title of the window
@param width The width of the framebuffer
@param height The height of the framebuffer
@return False on any errors, else true
*/
void initialize(const string& title, uInt32 width, uInt32 height);
bool initialize(const string& title, uInt32 width, uInt32 height);
/**
Updates the display, which depending on the current mode could mean

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: OSystem.cxx,v 1.130 2008-05-21 21:01:40 stephena Exp $
// $Id: OSystem.cxx,v 1.131 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#include <cassert>
@ -306,6 +306,7 @@ bool OSystem::createFrameBuffer(bool showmessage)
myFrameBuffer->type() != kGLBuffer))
changeBuffer = true;
}
// Now we only create when absolutely necessary
if(changeBuffer)
{
@ -320,16 +321,19 @@ bool OSystem::createFrameBuffer(bool showmessage)
case EventHandler::S_PAUSE:
case EventHandler::S_MENU:
case EventHandler::S_CMDMENU:
myConsole->initializeVideo();
if(!myConsole->initializeVideo())
return false;
break; // S_EMULATE, S_PAUSE, S_MENU, S_CMDMENU
case EventHandler::S_LAUNCHER:
myLauncher->initializeVideo();
if(!myLauncher->initializeVideo())
return false;
break; // S_LAUNCHER
#ifdef DEBUGGER_SUPPORT
case EventHandler::S_DEBUGGER:
myDebugger->initializeVideo();
if(!myDebugger->initializeVideo())
return false;
break; // S_DEBUGGER
#endif
@ -434,7 +438,11 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum)
myCheatManager->loadCheats(md5);
#endif
myEventHandler->reset(EventHandler::S_EMULATE);
createFrameBuffer(false); // Takes care of initializeVideo()
if(!createFrameBuffer(false)) // Takes care of initializeVideo()
{
cerr << "ERROR: Couldn't create framebuffer for console" << endl;
return false;
}
myConsole->initializeAudio();
#ifdef DEBUGGER_SUPPORT
myDebugger->setConsole(myConsole);
@ -456,13 +464,13 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum)
}
else
{
cerr << "ERROR: Couldn't create console for " << myRomFile << " ..." << endl;
cerr << "ERROR: Couldn't create console for " << myRomFile << endl;
retval = false;
}
}
else
{
cerr << "ERROR: Couldn't open " << myRomFile << " ..." << endl;
cerr << "ERROR: Couldn't open " << myRomFile << endl;
retval = false;
}
@ -497,16 +505,22 @@ void OSystem::deleteConsole()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::createLauncher()
bool OSystem::createLauncher()
{
myEventHandler->reset(EventHandler::S_LAUNCHER);
createFrameBuffer(false);
if(!createFrameBuffer(false))
{
cerr << "ERROR: Couldn't create launcher" << endl;
return false;
}
myLauncher->reStack();
myFrameBuffer->setCursorState();
myEventHandler->refreshDisplay();
setFramerate(60);
resetLoopTiming();
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: OSystem.hxx,v 1.66 2008-05-19 21:16:58 stephena Exp $
// $Id: OSystem.hxx,v 1.67 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#ifndef OSYSTEM_HXX
@ -56,7 +56,7 @@ typedef Common::Array<Resolution> ResolutionList;
other objects belong.
@author Stephen Anthony
@version $Id: OSystem.hxx,v 1.66 2008-05-19 21:16:58 stephena Exp $
@version $Id: OSystem.hxx,v 1.67 2008-05-30 19:07:55 stephena Exp $
*/
class OSystem
{
@ -317,8 +317,10 @@ class OSystem
/**
Creates a new ROM launcher, to select a new ROM to emulate.
@return True on successful creation, otherwise false
*/
void createLauncher();
bool createLauncher();
/**
Gets all possible info about the ROM by creating a temporary

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Settings.cxx,v 1.147 2008-05-21 16:49:07 stephena Exp $
// $Id: Settings.cxx,v 1.148 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#include <cassert>
@ -121,7 +121,7 @@ void Settings::loadConfig()
ifstream in(myOSystem->configFile().c_str());
if(!in || !in.is_open())
{
cout << "Error: Couldn't load settings file\n";
cout << "ERROR: Couldn't load settings file\n";
return;
}
@ -404,7 +404,7 @@ void Settings::saveConfig()
ofstream out(myOSystem->configFile().c_str());
if(!out || !out.is_open())
{
cout << "Error: Couldn't save settings file\n";
cout << "ERROR: Couldn't save settings file\n";
return;
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Switches.cxx,v 1.9 2008-02-06 13:45:22 stephena Exp $
// $Id: Switches.cxx,v 1.10 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#include "Event.hxx"
@ -116,7 +116,7 @@ bool Switches::save(Serializer& out) const
}
catch(...)
{
cerr << "Error: Switches::save() exception\n";
cerr << "ERROR: Switches::save() exception\n";
return false;
}
return true;
@ -131,7 +131,7 @@ bool Switches::load(Deserializer& in)
}
catch(...)
{
cerr << "Error: Switches::load() exception\n";
cerr << "ERROR: Switches::load() exception\n";
return false;
}
return true;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Launcher.cxx,v 1.22 2008-03-12 22:04:51 stephena Exp $
// $Id: Launcher.cxx,v 1.23 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#include <sstream>
@ -55,10 +55,10 @@ Launcher::~Launcher()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Launcher::initializeVideo()
bool Launcher::initializeVideo()
{
string title = string("Stella ") + STELLA_VERSION;
myOSystem->frameBuffer().initialize(title, myWidth, myHeight);
return myOSystem->frameBuffer().initialize(title, myWidth, myHeight);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Launcher.hxx,v 1.15 2008-03-12 22:04:51 stephena Exp $
// $Id: Launcher.hxx,v 1.16 2008-05-30 19:07:55 stephena Exp $
//============================================================================
#ifndef LAUNCHER_HXX
@ -28,7 +28,7 @@ class OSystem;
The base dialog for the ROM launcher in Stella.
@author Stephen Anthony
@version $Id: Launcher.hxx,v 1.15 2008-03-12 22:04:51 stephena Exp $
@version $Id: Launcher.hxx,v 1.16 2008-05-30 19:07:55 stephena Exp $
*/
class Launcher : public DialogContainer
{
@ -46,7 +46,7 @@ class Launcher : public DialogContainer
/**
Initialize the video subsystem wrt this class.
*/
void initializeVideo();
bool initializeVideo();
/**
Wrapper for LauncherDialog::selectedRomMD5() method.

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: LauncherDialog.cxx,v 1.86 2008-03-30 15:47:10 stephena Exp $
// $Id: LauncherDialog.cxx,v 1.87 2008-05-30 19:07:55 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -69,7 +69,7 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent,
myRomInfoFlag = instance()->settings().getBool("romviewer");
if((w < 640 || h < 480) && myRomInfoFlag)
{
cerr << "Error: ROM launcher too small, deactivating ROM info viewer" << endl;
cerr << "ERROR: ROM launcher too small, deactivating ROM info viewer" << endl;
myRomInfoFlag = false;
}