Misc: Clean up the last places exceptions were used

This commit is contained in:
Stenzek 2022-12-28 23:38:09 +10:00 committed by Connor McLaughlin
parent a889acb332
commit 2ae78f6e2f
12 changed files with 101 additions and 140 deletions

View File

@ -156,14 +156,7 @@ bool StartKeepAliveThread()
if (s_keepalive_is_open == false) if (s_keepalive_is_open == false)
{ {
s_keepalive_is_open = true; s_keepalive_is_open = true;
try s_keepalive_thread = std::thread(keepAliveThread);
{
s_keepalive_thread = std::thread(keepAliveThread);
}
catch (std::system_error&)
{
s_keepalive_is_open = false;
}
} }
return s_keepalive_is_open; return s_keepalive_is_open;
@ -190,21 +183,15 @@ s32 CALLBACK DISCopen(const char* pTitle)
return -1; return -1;
// open device file // open device file
try src = std::make_unique<IOCtlSrc>(std::move(drive));
{ if (!src->Reopen())
src = std::unique_ptr<IOCtlSrc>(new IOCtlSrc(drive));
}
catch (std::runtime_error&)
{
return -1;
}
//setup threading manager
if (!cdvdStartThread())
{ {
src.reset(); src.reset();
return -1; return -1;
} }
//setup threading manager
cdvdStartThread();
StartKeepAliveThread(); StartKeepAliveThread();
return cdvdRefreshData(); return cdvdRefreshData();
@ -312,16 +299,10 @@ s32 CALLBACK DISCgetTD(u8 Track, cdvdTD* Buffer)
{ {
if (src == nullptr) if (src == nullptr)
return -1; return -1;
try
{ Buffer->lsn = src->GetSectorCount();
Buffer->lsn = src->GetSectorCount(); Buffer->type = 0;
Buffer->type = 0; return 0;
return 0;
}
catch (...)
{
return -1;
}
} }
if (Track < strack) if (Track < strack)

View File

@ -64,12 +64,13 @@ class IOCtlSrc
bool ReadDVDInfo(); bool ReadDVDInfo();
bool ReadCDInfo(); bool ReadCDInfo();
bool Reopen();
public: public:
IOCtlSrc(std::string filename); IOCtlSrc(std::string filename);
~IOCtlSrc(); ~IOCtlSrc();
bool Reopen();
u32 GetSectorCount() const; u32 GetSectorCount() const;
const std::vector<toc_entry>& ReadTOC() const; const std::vector<toc_entry>& ReadTOC() const;
bool ReadSectors2048(u32 sector, u32 count, u8* buffer) const; bool ReadSectors2048(u32 sector, u32 count, u8* buffer) const;
@ -90,7 +91,7 @@ extern bool weAreInNewDiskCB;
extern void (*newDiscCB)(); extern void (*newDiscCB)();
bool cdvdStartThread(); void cdvdStartThread();
void cdvdStopThread(); void cdvdStopThread();
void cdvdRequestSector(u32 sector, s32 mode); void cdvdRequestSector(u32 sector, s32 mode);
u8* cdvdGetSector(u32 sector, s32 mode); u8* cdvdGetSector(u32 sector, s32 mode);

View File

@ -261,25 +261,15 @@ void cdvdThread()
printf(" * CDVD: IO thread finished.\n"); printf(" * CDVD: IO thread finished.\n");
} }
bool cdvdStartThread() void cdvdStartThread()
{ {
if (cdvd_is_open == false) if (cdvd_is_open == false)
{ {
cdvd_is_open = true; cdvd_is_open = true;
try s_thread = std::thread(cdvdThread);
{
s_thread = std::thread(cdvdThread);
}
catch (std::system_error&)
{
cdvd_is_open = false;
return false;
}
} }
cdvdCacheReset(); cdvdCacheReset();
return true;
} }
void cdvdStopThread() void cdvdStopThread()
@ -349,15 +339,8 @@ s32 cdvdDirectReadSector(u32 sector, s32 mode, u8* buffer)
if (src == nullptr) if (src == nullptr)
return -1; return -1;
try if (sector >= src->GetSectorCount())
{
if (sector >= src->GetSectorCount())
return -1;
}
catch (...)
{
return -1; return -1;
}
// Align to cache block // Align to cache block
u32 sector_block = sector & ~(sectors_per_read - 1); u32 sector_block = sector & ~(sectors_per_read - 1);

View File

@ -29,11 +29,9 @@
#include <cerrno> #include <cerrno>
#include <cstring> #include <cstring>
IOCtlSrc::IOCtlSrc(decltype(m_filename) filename) IOCtlSrc::IOCtlSrc(std::string filename)
: m_filename(filename) : m_filename(std::move(filename))
{ {
if (!Reopen())
throw std::runtime_error(" * CDVD: Error opening source.\n");
} }
IOCtlSrc::~IOCtlSrc() IOCtlSrc::~IOCtlSrc()

View File

@ -26,11 +26,9 @@
#include <climits> #include <climits>
#include <cstring> #include <cstring>
IOCtlSrc::IOCtlSrc(decltype(m_filename) filename) IOCtlSrc::IOCtlSrc(std::string filename)
: m_filename(filename) : m_filename(std::move(filename))
{ {
if (!Reopen())
throw std::runtime_error(" * CDVD: Error opening source.\n");
} }
IOCtlSrc::~IOCtlSrc() IOCtlSrc::~IOCtlSrc()

View File

@ -36,8 +36,6 @@
IOCtlSrc::IOCtlSrc(std::string filename) IOCtlSrc::IOCtlSrc(std::string filename)
: m_filename(std::move(filename)) : m_filename(std::move(filename))
{ {
if (!Reopen())
throw std::runtime_error(" * CDVD: Error opening source.\n");
} }
IOCtlSrc::~IOCtlSrc() IOCtlSrc::~IOCtlSrc()

View File

@ -908,50 +908,45 @@ void GameDatabaseSchema::GameEntry::applyGSHardwareFixes(Pcsx2Config::GSOptions&
void GameDatabase::initDatabase() void GameDatabase::initDatabase()
{ {
ryml::Callbacks rymlCallbacks = ryml::get_callbacks(); ryml::Callbacks rymlCallbacks = ryml::get_callbacks();
rymlCallbacks.m_error = [](const char* msg, size_t msg_len, ryml::Location loc, void*) { rymlCallbacks.m_error = [](const char* msg, size_t msg_len, ryml::Location loc, void* userdata) {
throw std::runtime_error(fmt::format("[YAML] Parsing error at {}:{} (bufpos={}): {}", Console.Error(fmt::format("[GameDB YAML] Parsing error at {}:{} (bufpos={}): {}",
loc.line, loc.col, loc.offset, msg)); loc.line, loc.col, loc.offset, std::string_view(msg, msg_len)));
}; };
ryml::set_callbacks(rymlCallbacks); ryml::set_callbacks(rymlCallbacks);
c4::set_error_callback([](const char* msg, size_t msg_size) { c4::set_error_callback([](const char* msg, size_t msg_size) {
throw std::runtime_error(fmt::format("[YAML] Internal Parsing error: {}", Console.Error(fmt::format("[GameDB YAML] Internal Parsing error: {}", std::string_view(msg, msg_size)));
msg));
}); });
try
auto buf = Host::ReadResourceFileToString(GAMEDB_YAML_FILE_NAME);
if (!buf.has_value())
{ {
auto buf = Host::ReadResourceFileToString(GAMEDB_YAML_FILE_NAME); Console.Error("[GameDB] Unable to open GameDB file, file does not exist.");
if (!buf.has_value()) return;
}
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(buf.value()));
ryml::NodeRef root = tree.rootref();
for (const ryml::NodeRef& n : root.children())
{
auto serial = StringUtil::toLower(std::string(n.key().str, n.key().len));
// Serials and CRCs must be inserted as lower-case, as that is how they are retrieved
// this is because the application may pass a lowercase CRC or serial along
//
// However, YAML's keys are as expected case-sensitive, so we have to explicitly do our own duplicate checking
if (s_game_db.count(serial) == 1)
{ {
Console.Error("[GameDB] Unable to open GameDB file, file does not exist."); Console.Error(fmt::format("[GameDB] Duplicate serial '{}' found in GameDB. Skipping, Serials are case-insensitive!", serial));
return; continue;
} }
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(buf.value())); if (n.is_map())
ryml::NodeRef root = tree.rootref();
for (const auto& n : root.children())
{ {
auto serial = StringUtil::toLower(std::string(n.key().str, n.key().len)); parseAndInsert(serial, n);
// Serials and CRCs must be inserted as lower-case, as that is how they are retrieved
// this is because the application may pass a lowercase CRC or serial along
//
// However, YAML's keys are as expected case-sensitive, so we have to explicitly do our own duplicate checking
if (s_game_db.count(serial) == 1)
{
Console.Error(fmt::format("[GameDB] Duplicate serial '{}' found in GameDB. Skipping, Serials are case-insensitive!", serial));
continue;
}
if (n.is_map())
{
parseAndInsert(serial, n);
}
} }
} }
catch (const std::exception& e)
{
Console.Error(fmt::format("[GameDB] Error occured when initializing GameDB: {}", e.what()));
}
ryml::reset_callbacks(); ryml::reset_callbacks();
} }

View File

@ -40,43 +40,37 @@
#include <mutex> #include <mutex>
#include <optional> #include <optional>
static ryml::Tree parseYamlStr(const std::string& str)
{
ryml::Callbacks rymlCallbacks = ryml::get_callbacks();
rymlCallbacks.m_error = [](const char* msg, size_t msg_len, ryml::Location loc, void*) {
throw std::runtime_error(fmt::format("[YAML] Parsing error at {}:{} (bufpos={}): {}",
loc.line, loc.col, loc.offset, msg));
};
ryml::set_callbacks(rymlCallbacks);
c4::set_error_callback([](const char* msg, size_t msg_size) {
throw std::runtime_error(fmt::format("[YAML] Internal Parsing error: {}",
msg));
});
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(str));
ryml::reset_callbacks();
return tree;
}
// A helper function to parse the YAML file // A helper function to parse the YAML file
static std::optional<ryml::Tree> loadYamlFile(const char* filePath) static std::optional<ryml::Tree> loadYamlFile(const char* filePath)
{ {
try std::optional<std::string> buffer = FileSystem::ReadFileToString(filePath);
if (!buffer.has_value())
return std::nullopt;
static u32 errorCount;
errorCount = 0;
ryml::Callbacks rymlCallbacks = ryml::get_callbacks();
rymlCallbacks.m_error = [](const char* msg, size_t msg_len, ryml::Location loc, void* userdata) {
Console.Error(fmt::format("[YAML] Parsing error at {}:{} (bufpos={}): {}",
loc.line, loc.col, loc.offset, std::string_view(msg, msg_len)));
errorCount++;
};
ryml::set_callbacks(rymlCallbacks);
c4::set_error_callback([](const char* msg, size_t msg_size) {
Console.Error(fmt::format("[YAML] Internal Parsing error: {}", std::string_view(msg, msg_size)));
errorCount++;
});
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(buffer.value()));
ryml::reset_callbacks();
if (errorCount > 0)
{ {
std::optional<std::string> buffer = FileSystem::ReadFileToString(filePath); Console.Error(fmt::format("[MemoryCard] Error occured when parsing folder memory card at path '{}'.", filePath));
if (!buffer.has_value())
{
return std::nullopt;
}
ryml::Tree tree = parseYamlStr(buffer.value());
return std::make_optional(tree);
}
catch (const std::exception& e)
{
Console.Error(fmt::format("[MemoryCard] Error occured when parsing folder memory card at path '{}': {}", filePath, e.what()));
ryml::reset_callbacks();
return std::nullopt; return std::nullopt;
} }
return tree;
} }
/// A helper function to write a YAML file /// A helper function to write a YAML file

View File

@ -366,7 +366,7 @@ extern void CPU_SET_DMASTALL(EE_EventType n, bool set);
extern uint intcInterrupt(); extern uint intcInterrupt();
extern uint dmacInterrupt(); extern uint dmacInterrupt();
extern void cpuReset(); // can throw Exception::FileNotFound. extern void cpuReset();
extern void cpuException(u32 code, u32 bd); extern void cpuException(u32 code, u32 bd);
extern void cpuTlbMissR(u32 addr, u32 bd); extern void cpuTlbMissR(u32 addr, u32 bd);
extern void cpuTlbMissW(u32 addr, u32 bd); extern void cpuTlbMissW(u32 addr, u32 bd);

View File

@ -1178,9 +1178,6 @@ void PREF()
static void trap(u16 code=0) static void trap(u16 code=0)
{ {
// unimplemented?
// throw R5900Exception::Trap(code);
cpuRegs.pc -= 4; cpuRegs.pc -= 4;
Console.Warning("Trap exception at 0x%08x", cpuRegs.pc); Console.Warning("Trap exception at 0x%08x", cpuRegs.pc);
cpuException(0x34, cpuRegs.branch); cpuException(0x34, cpuRegs.branch);

View File

@ -339,34 +339,45 @@ namespace usb_eyetoy
return 0; return 0;
} }
void DirectShow::Start() bool DirectShow::Start()
{ {
HRESULT hr = nullrenderer->Run(0); HRESULT hr = nullrenderer->Run(0);
if (FAILED(hr)) if (FAILED(hr))
throw hr; {
Console.Error("nullrenderer->Run() failed: %08X", hr);
return false;
}
hr = samplegrabberfilter->Run(0); hr = samplegrabberfilter->Run(0);
if (FAILED(hr)) if (FAILED(hr))
throw hr; {
Console.Error("samplegrabberfilter->Run() failed: %08X", hr);
return false;
}
hr = sourcefilter->Run(0); hr = sourcefilter->Run(0);
if (FAILED(hr)) if (FAILED(hr))
throw hr; {
Console.Error("sourcefilter->Run() failed: %08X", hr);
return false;
}
return true;
} }
void DirectShow::Stop() void DirectShow::Stop()
{ {
HRESULT hr = sourcefilter->Stop(); HRESULT hr = sourcefilter->Stop();
if (FAILED(hr)) if (FAILED(hr))
throw hr; Console.Error("sourcefilter->Stop() failed: %08X", hr);
hr = samplegrabberfilter->Stop(); hr = samplegrabberfilter->Stop();
if (FAILED(hr)) if (FAILED(hr))
throw hr; Console.Error("samplegrabberfilter->Stop() failed: %08X", hr);
hr = nullrenderer->Stop(); hr = nullrenderer->Stop();
if (FAILED(hr)) if (FAILED(hr))
throw hr; Console.Error("nullrenderer->Stop() failed: %08X", hr);
} }
void store_mpeg_frame(const unsigned char* data, const unsigned int len) void store_mpeg_frame(const unsigned char* data, const unsigned int len)
@ -551,9 +562,14 @@ namespace usb_eyetoy
} }
pControl->Run(); pControl->Run();
this->Stop(); Stop();
this->SetCallback(dshow_callback); SetCallback(dshow_callback);
this->Start(); if (!Start())
{
Console.Error("Camera: Failed to start");
Stop();
return -1;
}
return 0; return 0;
}; };

View File

@ -90,7 +90,7 @@ namespace usb_eyetoy
protected: protected:
void SetCallback(DShowVideoCaptureCallback cb) { callbackhandler->SetCallback(cb); } void SetCallback(DShowVideoCaptureCallback cb) { callbackhandler->SetCallback(cb); }
void Start(); bool Start();
void Stop(); void Stop();
int InitializeDevice(std::wstring selectedDevice); int InitializeDevice(std::wstring selectedDevice);