From bd8127f75e7fbd865af8b82cfc01545c658785ac Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Fri, 29 Oct 2010 02:49:01 +0000 Subject: [PATCH] newHostVM: More error/exception handling WIP stuff. git-svn-id: http://pcsx2.googlecode.com/svn/branches/newHostVM@3980 96395faa-99c1-11dd-bbfe-3dabce05a288 --- common/include/Utilities/Exceptions.h | 9 ++++-- common/include/Utilities/PageFaultSource.h | 3 +- common/include/Utilities/SafeArray.inl | 21 +++++++------ common/src/Utilities/Exceptions.cpp | 34 ++++++++++++++++++++-- pcsx2/Memory.cpp | 3 +- pcsx2/gui/AppInit.cpp | 3 +- pcsx2/x86/ix86-32/iR5900-32.cpp | 2 +- pcsx2/x86/sVU_zerorec.cpp | 2 +- 8 files changed, 56 insertions(+), 21 deletions(-) diff --git a/common/include/Utilities/Exceptions.h b/common/include/Utilities/Exceptions.h index ca73656774..be7951c720 100644 --- a/common/include/Utilities/Exceptions.h +++ b/common/include/Utilities/Exceptions.h @@ -209,7 +209,7 @@ public: \ // class OutOfMemory : public RuntimeError { - DEFINE_RUNTIME_EXCEPTION( OutOfMemory, RuntimeError, wxLt("Out of memory?!") ) + DEFINE_RUNTIME_EXCEPTION( OutOfMemory, RuntimeError, wxEmptyString ) public: wxString AllocDescription; @@ -236,7 +236,12 @@ public: \ // we'd really like to have access to. class VirtualMemoryMapConflict : public OutOfMemory { - DEFINE_RUNTIME_EXCEPTION( VirtualMemoryMapConflict, OutOfMemory, wxLt("Virtual memory map confict: Unable to claim specific required memory regions.") ) + DEFINE_RUNTIME_EXCEPTION( VirtualMemoryMapConflict, OutOfMemory, wxEmptyString ) + + VirtualMemoryMapConflict( const wxString& allocdesc ); + + virtual wxString FormatDisplayMessage() const; + virtual wxString FormatDiagnosticMessage() const; }; class HardwareDeficiency : public RuntimeError diff --git a/common/include/Utilities/PageFaultSource.h b/common/include/Utilities/PageFaultSource.h index bf64331fe2..5073744c51 100644 --- a/common/include/Utilities/PageFaultSource.h +++ b/common/include/Utilities/PageFaultSource.h @@ -133,7 +133,8 @@ public: virtual void Free(); bool IsOk() const { return m_baseptr != NULL; } - + wxString GetName() const { return Name; } + uptr GetReserveSizeInBytes() const { return m_reserved * __pagesize; } uptr GetReserveSizeInPages() const { return m_reserved; } diff --git a/common/include/Utilities/SafeArray.inl b/common/include/Utilities/SafeArray.inl index 259651176f..a381c47422 100644 --- a/common/include/Utilities/SafeArray.inl +++ b/common/include/Utilities/SafeArray.inl @@ -31,7 +31,8 @@ SafeArray::SafeArray( const wxChar* name, T* allocated_mem, int initSize ) m_size = initSize; if( m_ptr == NULL ) - throw Exception::OutOfMemory(name + wxsFormat(L" (SafeArray::constructor) [size=%d]", initSize)); + throw Exception::OutOfMemory(name) + .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ctor' [size=%d]", initSize)); } template< typename T > @@ -79,7 +80,8 @@ SafeArray::SafeArray( int initialSize, const wxChar* name ) m_size = initialSize; if( (initialSize != 0) && (m_ptr == NULL) ) - throw Exception::OutOfMemory(name + wxsFormat(L" (SafeArray::constructor) [size=%d]", initialSize)); + throw Exception::OutOfMemory(name) + .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ctor' [size=%d]", initialSize)); } // Clears the contents of the array to zero, and frees all memory allocations. @@ -106,9 +108,8 @@ void SafeArray::ExactAlloc( int newsize ) m_ptr = _virtual_realloc( newsize ); if( m_ptr == NULL ) - throw Exception::OutOfMemory(Name + - wxsFormat(L" (SafeArray::ExactAlloc) [oldsize=%d] [newsize=%d]", m_size, newsize) - ); + throw Exception::OutOfMemory(Name) + .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ExactAlloc' [oldsize=%d] [newsize=%d]", m_size, newsize)); m_size = newsize; } @@ -199,9 +200,8 @@ SafeList::SafeList( int initialSize, const wxChar* name ) m_ptr = (T*)malloc( initialSize * sizeof(T) ); if( m_ptr == NULL ) - throw Exception::OutOfMemory(Name + - wxsFormat(L" (SafeList::Constructor) [length=%d]", m_length) - ); + throw Exception::OutOfMemory(Name) + .SetDiagMsg(wxsFormat(L"called from 'SafeList::ctor' [length=%d]", m_length)); for( int i=0; i::MakeRoomFor( int blockSize ) const int newalloc = blockSize + ChunkSize; m_ptr = _virtual_realloc( newalloc ); if( m_ptr == NULL ) - throw Exception::OutOfMemory(Name + - wxsFormat(L" (SafeList::MakeRoomFor) [oldlen=%d] [newlen=%d]", m_length, blockSize) - ); + throw Exception::OutOfMemory(Name) + .SetDiagMsg(wxsFormat(L"Called from 'SafeList::MakeRoomFor' [oldlen=%d] [newlen=%d]", m_length, blockSize)); for( ; m_allocsize failed to allocate PS2's base ram/rom/scratchpad." ); + throw Exception::OutOfMemory( L"PS2 Main Memory (VTLB)" ) + .SetUserMsg(L"Could not allocate memory needed for the PS2 virtual machine's main memory (approx. 42mb)."); pxAssume(Source_PageFault); mmap_faultHandler = new mmap_PageFaultHandler(); diff --git a/pcsx2/gui/AppInit.cpp b/pcsx2/gui/AppInit.cpp index 8b448aa737..755907a65b 100644 --- a/pcsx2/gui/AppInit.cpp +++ b/pcsx2/gui/AppInit.cpp @@ -531,8 +531,9 @@ bool Pcsx2App::OnInit() g_Conf = new AppConfig(); wxInitAllImageHandlers(); - Console.WriteLn("Begin parsing commandline..."); + Console.WriteLn("Command line parsing..."); if( !_parent::OnInit() ) return false; + Console.WriteLn("Command line parsed!"); wxLocale::AddCatalogLookupPathPrefix( wxGetCwd() ); diff --git a/pcsx2/x86/ix86-32/iR5900-32.cpp b/pcsx2/x86/ix86-32/iR5900-32.cpp index d30b998a65..d07e3039b2 100644 --- a/pcsx2/x86/ix86-32/iR5900-32.cpp +++ b/pcsx2/x86/ix86-32/iR5900-32.cpp @@ -577,7 +577,7 @@ static void recReserveCache() if (!recMem->IsOk()) { - throw Exception::VirtualMemoryMapConflict() + throw Exception::VirtualMemoryMapConflict(recMem->GetName()) .SetDiagMsg(pxsFmt( L"R5900-32 recompiled code cache could not be mapped." )) .SetUserMsg(GetMsg_RecVmFailed("R5900-32")); } diff --git a/pcsx2/x86/sVU_zerorec.cpp b/pcsx2/x86/sVU_zerorec.cpp index 43e1bf55e6..5183167940 100644 --- a/pcsx2/x86/sVU_zerorec.cpp +++ b/pcsx2/x86/sVU_zerorec.cpp @@ -357,7 +357,7 @@ static void SuperVUAlloc(int vuindex) if (!s_recVUMem[vuindex]->IsOk()) { safe_delete(s_recVUMem[vuindex]); - throw Exception::VirtualMemoryMapConflict() + throw Exception::VirtualMemoryMapConflict( s_recVUMem[vuindex]->GetName() ) .SetDiagMsg(pxsFmt( L"SuperVU failed to allocate virtual memory below 256MB." )) .SetUserMsg(pxE( ".Error:superVU:VirtualMemoryAlloc", L"Out of Memory (sorta): The SuperVU recompiler was unable to reserve the specific memory "