(svn r11611) -Codechange: it is now possible to use a define to enable asserts and show them in crash.log for MSVC release builds
authorglx
Sun, 09 Dec 2007 21:20:21 +0000
changeset 8547 41d5e08fff3b
parent 8546 2a09d7d2a341
child 8548 55a6ec4ec456
(svn r11611) -Codechange: it is now possible to use a define to enable asserts and show them in crash.log for MSVC release builds
src/blitter/factory.hpp
src/driver.h
src/stdafx.h
src/win32.cpp
--- a/src/blitter/factory.hpp	Sun Dec 09 20:20:52 2007 +0000
+++ b/src/blitter/factory.hpp	Sun Dec 09 21:20:21 2007 +0000
@@ -41,7 +41,7 @@
 		if (name == NULL) return;
 
 		this->name = strdup(name);
-#if !defined(NDEBUG)
+#if !defined(NDEBUG) || defined(WITH_ASSERT)
 		/* NDEBUG disables asserts and gives a warning: unused variable 'P' */
 		std::pair<Blitters::iterator, bool> P =
 #endif /* !NDEBUG */
--- a/src/driver.h	Sun Dec 09 20:20:52 2007 +0000
+++ b/src/driver.h	Sun Dec 09 21:20:21 2007 +0000
@@ -79,7 +79,7 @@
 		strecpy(buf, GetDriverTypeName(type), lastof(buf));
 		strecpy(buf + 5, name, lastof(buf));
 
-#if !defined(NDEBUG)
+#if !defined(NDEBUG) || defined(WITH_ASSERT)
 		/* NDEBUG disables asserts and gives a warning: unused variable 'P' */
 		std::pair<Drivers::iterator, bool> P =
 #endif /* !NDEBUG */
--- a/src/stdafx.h	Sun Dec 09 20:20:52 2007 +0000
+++ b/src/stdafx.h	Sun Dec 09 21:20:21 2007 +0000
@@ -207,6 +207,13 @@
 		#define strcasecmp stricmp
 		#define strncasecmp strnicmp
 	#endif
+
+	void SetExceptionString(const char* s, ...);
+
+	#if defined(NDEBUG) && defined(WITH_ASSERT)
+		#undef assert
+		#define assert(expression) if (!(expression)) { SetExceptionString("Assertion failed at %s:%d: %s", __FILE__, __LINE__, #expression); *(byte*)0 = 0; }
+	#endif
 #endif /* defined(_MSC_VER) */
 
 #if defined(WINCE)
--- a/src/win32.cpp	Sun Dec 09 20:20:52 2007 +0000
+++ b/src/win32.cpp	Sun Dec 09 21:20:21 2007 +0000
@@ -81,6 +81,17 @@
 
 #ifdef _MSC_VER
 static const char *_exception_string = NULL;
+void SetExceptionString(const char *s, ...)
+{
+	va_list va;
+	char buf[512];
+
+	va_start(va, s);
+	vsnprintf(buf, lengthof(buf), s, va);
+	va_end(va);
+
+	_exception_string = strdup(buf);
+}
 #endif
 
 void ShowOSErrorBox(const char *buf)