From a2620241352dd329519e9aabb9283a3dac452262 Mon Sep 17 00:00:00 2001 From: wowzaman12 Date: Sat, 28 Mar 2015 01:33:12 +0000 Subject: [PATCH] Added more pointer error checking to the wxvbam build. git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@1260 a31d4220-a93d-0410-bf67-fe4944624d44 --- src/wx/sys.cpp | 2 +- src/wx/wxvbam.cpp | 1 + src/wx/wxvbam.h | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/wx/sys.cpp b/src/wx/sys.cpp index d9a9bd2f..364e3bbc 100644 --- a/src/wx/sys.cpp +++ b/src/wx/sys.cpp @@ -474,7 +474,7 @@ class PrintDialog : public wxEvtHandler, public wxPrintout public: PrintDialog(const u16 *data, int lines, bool cont); ~PrintDialog(); - int ShowModal() { return wxGetApp().frame->ShowModal(dlg); } + int ShowModal() {CheckPointer(wxGetApp().frame); return wxGetApp().frame->ShowModal(dlg); } private: void DoSave(wxCommandEvent&); void DoPrint(wxCommandEvent&); diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 33f5a7f0..a06bd075 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -616,6 +616,7 @@ void MainFrame::MenuPopped(wxMenuEvent &evt) // uses dialog_opened as a nesting counter int MainFrame::ShowModal(wxDialog *dlg) { + CheckPointer(dlg); StartModal(); int ret = dlg->ShowModal(); StopModal(); diff --git a/src/wx/wxvbam.h b/src/wx/wxvbam.h index 98413d55..df6f9287 100644 --- a/src/wx/wxvbam.h +++ b/src/wx/wxvbam.h @@ -2,6 +2,8 @@ #define WX_WXVBAM_H #include +#include +#include #include #include "wxhead.h" @@ -25,6 +27,18 @@ #include "../gb/gbCheats.h" #include "../gba/Cheats.h" +template +void CheckPointer(T pointer) +{ + if(pointer == NULL) + { + std::string errormessage = "Pointer of type \""; + errormessage+=typeid(pointer).name(); + errormessage+="\" was not correctly created."; + throw std::runtime_error(errormessage); + } +} + class MainFrame; class wxvbamApp : public wxApp