Ver código fonte

Non-recursive function assertion

Michael Ragazzon 6 anos atrás
pai
commit
3535e59392
2 arquivos alterados com 17 adições e 9 exclusões
  1. 15 8
      Include/Rocket/Core/Debug.h
  2. 2 1
      Source/Core/StyleSheet.cpp

+ 15 - 8
Include/Rocket/Core/Debug.h

@@ -91,17 +91,24 @@ if (!Rocket::Core::Assert(m, __FILE__, __LINE__)) \
 }
 #define ROCKET_VERIFY(x) ROCKET_ASSERT(x)
 
-}
-}
-#endif
+struct RocketAssertNonrecursive {
+	bool& entered;
+	RocketAssertNonrecursive(bool& entered) : entered(entered) {
+		ROCKET_ASSERTMSG(!entered, "A method defined as non-recursive was entered twice!");
+		entered = true;
+	}
+	~RocketAssertNonrecursive() {
+		entered = false;
+	}
+};
 
-namespace Rocket {
-namespace Core {
+#define ROCKET_ASSERT_NONRECURSIVE \
+static bool rocket_nonrecursive_entered = false; \
+RocketAssertNonrecursive rocket_nonrecursive(rocket_nonrecursive_entered)
 
-template <bool> struct STATIC_ASSERTION_FAILURE;
-template <> struct STATIC_ASSERTION_FAILURE<true>{};	
-	
 }
 }
+#endif
+
 
 #endif

+ 2 - 1
Source/Core/StyleSheet.cpp

@@ -121,6 +121,8 @@ Keyframes * StyleSheet::GetKeyframes(const String & name) {
 // Returns the compiled element definition for a given element hierarchy.
 ElementDefinition* StyleSheet::GetElementDefinition(const Element* element) const
 {
+	ROCKET_ASSERT_NONRECURSIVE;
+
 	// Address cache is disabled for the time being; this doesn't work since the introduction of structural
 	// pseudo-classes.
 	ElementDefinitionCache::iterator cache_iterator;
@@ -138,7 +140,6 @@ ElementDefinition* StyleSheet::GetElementDefinition(const Element* element) cons
 	// See if there are any styles defined for this element.
 	// Using static to avoid allocations. Make sure we don't call this function recursively.
 	static std::vector< const StyleSheetNode* > applicable_nodes;
-	ROCKET_ASSERT(applicable_nodes.empty());
 	applicable_nodes.clear();
 
 	String tags[] = {element->GetTagName(), ""};