mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-13 14:07:01 -04:00
Don't show message boxes for assertion failures, since this can lead to crashes when in OnPaint
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1197 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -72,7 +72,9 @@ void CardViewer::onChangeSize() {
|
|||||||
void CardViewer::onPaint(wxPaintEvent&) {
|
void CardViewer::onPaint(wxPaintEvent&) {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// we don't want recursion
|
// we don't want recursion
|
||||||
assert(!inOnPaint());
|
if (inOnPaint()) {
|
||||||
|
wxTrap();
|
||||||
|
}
|
||||||
WITH_DYNAMIC_ARG(inOnPaint, true);
|
WITH_DYNAMIC_ARG(inOnPaint, true);
|
||||||
#endif
|
#endif
|
||||||
wxSize cs = GetClientSize();
|
wxSize cs = GetClientSize();
|
||||||
@@ -129,7 +131,9 @@ class CardViewer::OverdrawDC : private OverdrawDC_aux, public RotatedDC {
|
|||||||
shared_ptr<RotatedDC> CardViewer::overdrawDC() {
|
shared_ptr<RotatedDC> CardViewer::overdrawDC() {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// don't call from onPaint
|
// don't call from onPaint
|
||||||
assert(!inOnPaint());
|
if (inOnPaint()) {
|
||||||
|
wxTrap();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return shared_ptr<RotatedDC>(new OverdrawDC(this));
|
return shared_ptr<RotatedDC>(new OverdrawDC(this));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ class MSE : public wxApp {
|
|||||||
int OnExit();
|
int OnExit();
|
||||||
/// On exception: display error message
|
/// On exception: display error message
|
||||||
bool OnExceptionInMainLoop();
|
bool OnExceptionInMainLoop();
|
||||||
|
/// Fancier assert
|
||||||
|
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||||
|
void OnAssert(const wxChar *file, int line, const wxChar *cond, const wxChar *msg);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
IMPLEMENT_APP(MSE)
|
IMPLEMENT_APP(MSE)
|
||||||
@@ -265,3 +269,18 @@ bool MSE::OnExceptionInMainLoop() {
|
|||||||
} CATCH_ALL_ERRORS(true);
|
} CATCH_ALL_ERRORS(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||||
|
// Print assert failures to debug output
|
||||||
|
void msvc_assert(const char*, const char*, const char*, unsigned);
|
||||||
|
void MSE::OnAssert(const wxChar *file, int line, const wxChar *cond, const wxChar *msg) {
|
||||||
|
#ifdef UNICODE
|
||||||
|
char file_[1024]; wcstombs(file_,file,1023);
|
||||||
|
char cond_[1024]; wcstombs(cond_,cond,1023);
|
||||||
|
char msg_ [1024]; wcstombs(msg_, msg, 1023);
|
||||||
|
msvc_assert(msg_, cond_, file_, line);
|
||||||
|
#else
|
||||||
|
msvc_assert(msg, cond, file, line);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -12,6 +12,25 @@
|
|||||||
|
|
||||||
DECLARE_TYPEOF_COLLECTION(ScriptParseError);
|
DECLARE_TYPEOF_COLLECTION(ScriptParseError);
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : Debug utilities
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||||
|
void msvc_assert(const char* msg, const char* expr, const char* file, unsigned line) {
|
||||||
|
if (IsDebuggerPresent()) {
|
||||||
|
char buffer[1024];
|
||||||
|
if (msg) {
|
||||||
|
sprintf(buffer, "Assertion failed: %s: %s, file %s, line %d\n", msg, expr, file, line);
|
||||||
|
} else {
|
||||||
|
sprintf(buffer, "Assertion failed: %s, file %s, line %d\n", expr, file, line);
|
||||||
|
}
|
||||||
|
OutputDebugStringA(buffer);
|
||||||
|
DebugBreak();
|
||||||
|
} else {
|
||||||
|
_assert(expr, file, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Error types
|
// ----------------------------------------------------------------------------- : Error types
|
||||||
|
|
||||||
Error::Error(const String& message)
|
Error::Error(const String& message)
|
||||||
|
|||||||
+14
-5
@@ -80,12 +80,21 @@ class FileName : public wxString {
|
|||||||
#include "reflect.hpp"
|
#include "reflect.hpp"
|
||||||
#include "regex.hpp"
|
#include "regex.hpp"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : Debugging fixes
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
//# pragma conform(forScope,on) // in "for(int x=..);" x goes out of scope after the for
|
//# pragma conform(forScope,on) // in "for(int x=..);" x goes out of scope after the for
|
||||||
// somehow forScope pragma doesn't work in precompiled headers, use this hack instead:
|
// somehow forScope pragma doesn't work in precompiled headers, use this hack instead:
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define for if(false);else for
|
#define for if(false);else for
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
// Use OutputDebugString/DebugBreak for assertions if in debug mode
|
||||||
|
void msvc_assert(const char*, const char*, const char*, unsigned);
|
||||||
|
#undef assert
|
||||||
|
#define assert(exp) (void)( (exp) || (msvc_assert(nullptr, #exp, __FILE__, __LINE__), 0) )
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : EOF
|
// ----------------------------------------------------------------------------- : EOF
|
||||||
|
|||||||
@@ -54,6 +54,9 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Regex() {}
|
||||||
|
inline Regex(const String& code) { assign(code); }
|
||||||
|
|
||||||
void assign(const String& code);
|
void assign(const String& code);
|
||||||
inline bool matches(const String& str) const {
|
inline bool matches(const String& str) const {
|
||||||
return regex_search(str.begin(), str.end(), regex);
|
return regex_search(str.begin(), str.end(), regex);
|
||||||
@@ -126,6 +129,9 @@
|
|||||||
friend class ScriptRegex;
|
friend class ScriptRegex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Regex() {}
|
||||||
|
inline Regex(const String& code) { assign(code); }
|
||||||
|
|
||||||
void assign(const String& code);
|
void assign(const String& code);
|
||||||
inline bool matches(const String& str) const {
|
inline bool matches(const String& str) const {
|
||||||
return regex.Matches(str);
|
return regex.Matches(str);
|
||||||
|
|||||||
Reference in New Issue
Block a user