]> git.sesse.net Git - casparcg/blobdiff - core/producer/binding.h
[scene] Fixed double evaluation of expressions
[casparcg] / core / producer / binding.h
index 71e31f2035942e76c63336993561ab265b521b73..17c9cff199a40a306d3125b24d6bbd67d44acab7 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdexcept>
 
 #include <boost/lexical_cast.hpp>
+#include <boost/utility/value_init.hpp>
 
 #include <common/tweener.h>
 #include <common/except.h>
@@ -99,7 +100,7 @@ private:
                mutable bool            evaluated_              = false;
 
                impl()
-                       : value_()
+                       : value_(boost::value_initialized<T>())
                {
                }
 
@@ -110,7 +111,8 @@ private:
 
                template<typename Expr>
                impl(const Expr& expression)
-                       : expression_(expression)
+                       : value_(boost::value_initialized<T>())
+                       , expression_(expression)
                {
                }
 
@@ -142,18 +144,20 @@ private:
 
                void evaluate() const override
                {
-                       if (expression_)
+                       if (bound())
                        {
                                auto new_value = expression_();
 
+                               evaluated_ = true;
+
                                if (new_value != value_)
                                {
                                        value_ = new_value;
                                        on_change();
                                }
                        }
-
-                       evaluated_ = true;
+                       else
+                               evaluated_ = true;
                }
 
                using impl_base::on_change;
@@ -182,7 +186,7 @@ private:
 
                void unbind()
                {
-                       if (expression_)
+                       if (bound())
                        {
                                expression_ = std::function<T ()>();
                                dependencies_.clear();