]> git.tdb.fi Git - libs/game.git/blobdiff - source/game/owned.h
Enforce no creation or destruction of objects during tick
[libs/game.git] / source / game / owned.h
index 7159c7d9622a06fd83301b7565dc1d55c0beedcc..fc2acab6ecb02ab0d4079630dae5f5fe5b8fc939 100644 (file)
@@ -2,6 +2,7 @@
 #define MSP_GAME_OWNED_H_
 
 #include <stdexcept>
+#include "accessguard.h"
 #include "events.h"
 #include "handle.h"
 #include "stage.h"
@@ -43,6 +44,10 @@ template<typename T>
 template<typename P, typename... Args>
 Owned<T>::Owned(Handle<P> parent, Args &&... args)
 {
+#ifdef DEBUG
+       AccessGuard::get_instance().check<AccessGuard::Create>();
+#endif
+
        if(!parent)
                throw std::invalid_argument("Owned::Owned");
 
@@ -89,6 +94,10 @@ void Owned<T>::destroy()
        if(!obj)
                return;
 
+#ifdef DEBUG
+       AccessGuard::get_instance().check<AccessGuard::Destroy>();
+#endif
+
        Stage &stage = get_stage(*obj);
 
        if constexpr(std::is_base_of_v<Component, T>)