diff --git a/src/TopicTree.h b/src/TopicTree.h index 6157aa9..463f7e7 100644 --- a/src/TopicTree.h +++ b/src/TopicTree.h @@ -250,7 +250,6 @@ private: /* Do we have a terminating wildcard child? */ if (iterator->terminatingWildcardChild) { - iterator->terminatingWildcardChild->messages[messageId] = message; /* Add this topic to triggered */ if (!iterator->terminatingWildcardChild->triggered) { @@ -263,6 +262,9 @@ private: iterator->terminatingWildcardChild->triggered = true; } + /* Above drain can reset messageId so we have to add new messages after */ + iterator->terminatingWildcardChild->messages[messageId] = message; + didMatch = true; } @@ -281,7 +283,6 @@ private: } /* If we went all the way we matched exactly */ - iterator->messages[messageId] = message; /* Add this topic to triggered */ if (!iterator->triggered) { @@ -294,6 +295,9 @@ private: iterator->triggered = true; } + /* Above drain can change messageId to 0, so we put the message after */ + iterator->messages[messageId] = message; + /* We obviously matches exactly here */ return true; }