From f15d1ec7a5a3e87aa0f01eedbac157d83f48c9cf Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Mon, 25 Feb 2019 09:17:06 -0330 Subject: [PATCH 1/2] Fixed crash in ROM launcher when openROM failed (typically on 0-byte file). --- src/gui/RomInfoWidget.cxx | 47 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/gui/RomInfoWidget.cxx b/src/gui/RomInfoWidget.cxx index 14528c4f8..13e1b81d8 100644 --- a/src/gui/RomInfoWidget.cxx +++ b/src/gui/RomInfoWidget.cxx @@ -126,31 +126,32 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node) myRomInfo.push_back("Note: " + myProperties.get(Cartridge_Note)); bool swappedPorts = myProperties.get(Console_SwapPorts) == "YES"; - string left = myProperties.get(Controller_Left); - string right = myProperties.get(Controller_Right); - - // load the image for auto detection - BytePtr image; - string md5 = myProperties.get(Cartridge_MD5); - uInt32 size = 0; - - if(node.exists() && !node.isDirectory() && (image = instance().openROM(node, md5, size)) != nullptr) + // Load the image for controller auto detection + try { - left = ControllerDetector::detectName(image.get(), size, left, - !swappedPorts ? Controller::Jack::Left : Controller::Jack::Right, - instance().settings()); - right = ControllerDetector::detectName(image.get(), size, right, - !swappedPorts ? Controller::Jack::Right : Controller::Jack::Left, - instance().settings()); + BytePtr image; + string md5 = myProperties.get(Cartridge_MD5); + uInt32 size = 0; + + string left = myProperties.get(Controller_Left); + string right = myProperties.get(Controller_Right); + if(node.exists() && !node.isDirectory() && + (image = instance().openROM(node, md5, size)) != nullptr) + { + left = ControllerDetector::detectName(image.get(), size, left, + !swappedPorts ? Controller::Jack::Left : Controller::Jack::Right, + instance().settings()); + right = ControllerDetector::detectName(image.get(), size, right, + !swappedPorts ? Controller::Jack::Right : Controller::Jack::Left, + instance().settings()); + } + myRomInfo.push_back("Controllers: " + (left + " (left), " + right + " (right)")); + } + catch(const runtime_error&) + { + // Do nothing; we simply don't update the controllers if openROM + // failed for any reason } - myRomInfo.push_back("Controllers: " + (left + " (left), " + right + " (right)")); - -#if 0 - myRomInfo.push_back("YStart/Height: " + myProperties.get(Display_YStart) + - " " + myProperties.get(Display_Height)); -#endif - - setDirty(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From ae589e165543c98b3b0d5839889c57c16d92ab8b Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Mon, 25 Feb 2019 09:31:14 -0330 Subject: [PATCH 2/2] Some fixes to last commit - if autodetection fails, we still want to see what was set in properties - if type is not set to 'AUTO', we don't want to autodetect at all --- src/gui/RomInfoWidget.cxx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/gui/RomInfoWidget.cxx b/src/gui/RomInfoWidget.cxx index 13e1b81d8..c98ae0fcf 100644 --- a/src/gui/RomInfoWidget.cxx +++ b/src/gui/RomInfoWidget.cxx @@ -127,31 +127,35 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node) bool swappedPorts = myProperties.get(Console_SwapPorts) == "YES"; // Load the image for controller auto detection + string left = myProperties.get(Controller_Left); + string right = myProperties.get(Controller_Right); try { BytePtr image; string md5 = myProperties.get(Cartridge_MD5); uInt32 size = 0; - string left = myProperties.get(Controller_Left); - string right = myProperties.get(Controller_Right); if(node.exists() && !node.isDirectory() && (image = instance().openROM(node, md5, size)) != nullptr) { - left = ControllerDetector::detectName(image.get(), size, left, - !swappedPorts ? Controller::Jack::Left : Controller::Jack::Right, - instance().settings()); - right = ControllerDetector::detectName(image.get(), size, right, - !swappedPorts ? Controller::Jack::Right : Controller::Jack::Left, - instance().settings()); + if(BSPF::equalsIgnoreCase(left, "AUTO")) + left = ControllerDetector::detectName(image.get(), size, left, + !swappedPorts ? Controller::Jack::Left : Controller::Jack::Right, + instance().settings()); + if(BSPF::equalsIgnoreCase(right, "AUTO")) + right = ControllerDetector::detectName(image.get(), size, right, + !swappedPorts ? Controller::Jack::Right : Controller::Jack::Left, + instance().settings()); } - myRomInfo.push_back("Controllers: " + (left + " (left), " + right + " (right)")); } catch(const runtime_error&) { // Do nothing; we simply don't update the controllers if openROM // failed for any reason + left = right = ""; } + if(left != "" && right != "") + myRomInfo.push_back("Controllers: " + (left + " (left), " + right + " (right)")); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -