summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2007-12-09 21:20:21 +0000
committerglx <glx@openttd.org>2007-12-09 21:20:21 +0000
commit15085aa7f47c06cb794a62a85240fdf12ca06bbc (patch)
tree9ac65ac4e5c5a30d1b8d89d7aa2e84d745e5abe7 /src
parent8bd26725d355b4b4aa0e31b4768497cad8e30b88 (diff)
downloadopenttd-15085aa7f47c06cb794a62a85240fdf12ca06bbc.tar.xz
(svn r11611) -Codechange: it is now possible to use a define to enable asserts and show them in crash.log for MSVC release builds
Diffstat (limited to 'src')
-rw-r--r--src/blitter/factory.hpp2
-rw-r--r--src/driver.h2
-rw-r--r--src/stdafx.h7
-rw-r--r--src/win32.cpp11
4 files changed, 20 insertions, 2 deletions
diff --git a/src/blitter/factory.hpp b/src/blitter/factory.hpp
index 494925613..8bb232e28 100644
--- a/src/blitter/factory.hpp
+++ b/src/blitter/factory.hpp
@@ -41,7 +41,7 @@ protected:
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 */
diff --git a/src/driver.h b/src/driver.h
index c05bfd2f8..640fc9c21 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -79,7 +79,7 @@ protected:
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 */
diff --git a/src/stdafx.h b/src/stdafx.h
index a9cd8feb5..f3a277d5e 100644
--- a/src/stdafx.h
+++ b/src/stdafx.h
@@ -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)
diff --git a/src/win32.cpp b/src/win32.cpp
index 0e3d4f4ef..b1e143d4f 100644
--- a/src/win32.cpp
+++ b/src/win32.cpp
@@ -81,6 +81,17 @@ bool LoadLibraryList(Function proc[], const char *dll)
#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)