瀏覽代碼

Remove assert from StringUtils ToVectorVariant() function and return empty variant in error case. Closes #1485. Convert assert in Log::SetLevel() to error logging, and remove assert from Log::Write().

Lasse Öörni 9 年之前
父節點
當前提交
63f71ab874
共有 3 個文件被更改,包括 11 次插入5 次删除
  1. 1 1
      Source/Urho3D/Core/StringUtils.cpp
  2. 2 2
      Source/Urho3D/Core/StringUtils.h
  3. 8 2
      Source/Urho3D/IO/Log.cpp

+ 1 - 1
Source/Urho3D/Core/StringUtils.cpp

@@ -399,7 +399,7 @@ Variant ToVectorVariant(const char* source)
         break;
 
     default:
-        assert(false);  // Should not get here
+        // Illegal input. Return variant remains empty
         break;
     }
 

+ 2 - 2
Source/Urho3D/Core/StringUtils.h

@@ -79,9 +79,9 @@ URHO3D_API Vector3 ToVector3(const char* source);
 URHO3D_API Vector4 ToVector4(const String& source, bool allowMissingCoords = false);
 /// Parse a Vector4 from a C string.
 URHO3D_API Vector4 ToVector4(const char* source, bool allowMissingCoords = false);
-/// Parse a float, Vector or Matrix variant from a string.
+/// Parse a float, Vector or Matrix variant from a string. Return empty variant on illegal input.
 URHO3D_API Variant ToVectorVariant(const String& source);
-/// Parse a float, Vector or Matrix variant from a C string.
+/// Parse a float, Vector or Matrix variant from a C string. Return empty variant on illegal input.
 URHO3D_API Variant ToVectorVariant(const char* source);
 /// Parse a Matrix3 from a string.
 URHO3D_API Matrix3 ToMatrix3(const String& source);

+ 8 - 2
Source/Urho3D/IO/Log.cpp

@@ -115,7 +115,11 @@ void Log::Close()
 
 void Log::SetLevel(int level)
 {
-    assert(level >= LOG_DEBUG && level < LOG_NONE);
+    if (level < LOG_DEBUG || level > LOG_NONE)
+    {
+        URHO3D_LOGERRORF("Attempted to set erroneous log level %d", level);
+        return;
+    }
 
     level_ = level;
 }
@@ -139,7 +143,9 @@ void Log::Write(int level, const String& message)
         return;
     }
 
-    assert(level >= LOG_DEBUG && level < LOG_NONE);
+    // No-op if illegal level
+    if (level < LOG_DEBUG || level >= LOG_NONE)
+        return;
 
     // If not in the main thread, store message for later processing
     if (!Thread::IsMainThread())