Browse Source

Re-enable ROCKET_ASSERT in debug builds. Correctly handle asserts on Win32, so it stops the application.

Lloyd Weehuizen 15 years ago
parent
commit
0fb91765b9

+ 0 - 5
Include/Rocket/Core/Log.h

@@ -71,11 +71,6 @@ public:
 	/// @param[in] line_number Line the error occured on.
 	/// @param[in] line_number Line the error occured on.
 	/// @param[in] format The error message, with sprintf-style parameters.
 	/// @param[in] format The error message, with sprintf-style parameters.
 	static void ParseError(const String& filename, int line_number, const char* format, ...);
 	static void ParseError(const String& filename, int line_number, const char* format, ...);
-
-	/// Low-level platform message. This completely bypasses the log interface and is only used if
-	/// there was an error talking to the log interface.
-	/// @param[in] message Message to output.
-	static void PlatformMessage(const char* message);
 };
 };
 
 
 }
 }

+ 1 - 0
Include/Rocket/Core/StringBase.h

@@ -29,6 +29,7 @@
 #define ROCKETCORESTRINGBASE_H
 #define ROCKETCORESTRINGBASE_H
 
 
 #include <Rocket/Core/Debug.h>
 #include <Rocket/Core/Debug.h>
+#include <stdlib.h>
 
 
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {

+ 4 - 9
Source/Core/Log.cpp

@@ -63,7 +63,7 @@ void Log::Message(Log::Type type, const char* fmt, ...)
 	buffer[len] = '\0';
 	buffer[len] = '\0';
 	va_end(argument_list);
 	va_end(argument_list);
 
 
-	Rocket::Core::GetSystemInterface()->LogMessage(type, buffer);
+	GetSystemInterface()->LogMessage(type, buffer);
 }
 }
 
 
 // Log a parse error on the specified file and line number.
 // Log a parse error on the specified file and line number.
@@ -89,15 +89,10 @@ void Log::ParseError(const String& filename, int line_number, const char* fmt, .
 		Message(Log::LT_ERROR, "%s: %s", filename.CString(), buffer);
 		Message(Log::LT_ERROR, "%s: %s", filename.CString(), buffer);
 }
 }
 
 
-// Low-level platform message.
-void Log::PlatformMessage(const char *message)
+bool Assert(const char* msg, const char* file, int line)
 {
 {
-#ifdef ROCKET_PLATFORM_WIN32
-	OutputDebugStringA(message);
-	OutputDebugStringA("\r\n");
-#else
-	fprintf(stderr,"%s\n", message);
-#endif	
+	Rocket::Core::String message(1024, "%s\n%s:%d", msg, file, line);
+	return GetSystemInterface()->LogMessage(Log::LT_ASSERT, message);
 }
 }
 
 
 }
 }

+ 22 - 2
Source/Core/SystemInterface.cpp

@@ -29,6 +29,10 @@
 #include <Rocket/Core/SystemInterface.h>
 #include <Rocket/Core/SystemInterface.h>
 #include <Rocket/Core/Log.h>
 #include <Rocket/Core/Log.h>
 
 
+#ifdef ROCKET_PLATFORM_WIN32
+#include <windows.h>
+#endif
+
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
 
 
@@ -40,10 +44,26 @@ SystemInterface::~SystemInterface()
 {
 {
 }
 }
 
 
-bool SystemInterface::LogMessage(Log::Type ROCKET_UNUSED(logtype), const String& message)
+bool SystemInterface::LogMessage(Log::Type logtype, const String& message)
 {
 {
 	// By default we just send a platform message
 	// By default we just send a platform message
-	Log::PlatformMessage(message.CString());
+#ifdef ROCKET_PLATFORM_WIN32
+	if (logtype == Log::LT_ASSERT)
+	{
+		Core::String message(1024, "%s\nWould you like to interrupt execution?", message.CString());	
+
+		// Return TRUE if the user presses NO (continue execution)
+		return (IDNO == MessageBoxA(NULL, message.CString(), "Assertion Failure", MB_YESNO | MB_ICONSTOP | MB_DEFBUTTON2 | MB_TASKMODAL));
+	}
+	else
+	{
+		OutputDebugStringA(message.CString());
+		OutputDebugStringA("\r\n");
+	}
+#else
+	(logtype);
+	fprintf(stderr,"%s\n", message);
+#endif	
 	return true;
 	return true;
 }
 }
 
 

+ 3 - 3
Source/Core/Variant.cpp

@@ -34,9 +34,9 @@ namespace Core {
 Variant::Variant() : type(NONE)
 Variant::Variant() : type(NONE)
 {
 {
 	// Make sure our object size assumptions fit inside the static buffer
 	// Make sure our object size assumptions fit inside the static buffer
-	ROCKET_STATIC_ASSERT(sizeof(Colourb) <= LOCAL_DATA_SIZE, Invalid_Size_Colourb);
-	ROCKET_STATIC_ASSERT(sizeof(Colourf) <= LOCAL_DATA_SIZE, Invalid_Size_Colourf);
-	ROCKET_STATIC_ASSERT(sizeof(String) <= LOCAL_DATA_SIZE, Invalid_Size_Colourf);
+	ROCKET_STATIC_ASSERT(sizeof(Colourb) <= LOCAL_DATA_SIZE, LOCAL_DATA_TOO_SMALL_FOR_Colourb);
+	ROCKET_STATIC_ASSERT(sizeof(Colourf) <= LOCAL_DATA_SIZE, LOCAL_DATA_TOO_SMALL_FOR_Colourf);
+	ROCKET_STATIC_ASSERT(sizeof(String) <= LOCAL_DATA_SIZE, LOCAL_DATA_TOO_SMALL_FOR_String);
 }
 }
 
 
 Variant::Variant( const Variant& copy ) : type(NONE)
 Variant::Variant( const Variant& copy ) : type(NONE)