- let's better add a null check to Create<> in case allocation or construction fails. Although unlikely it's not impossible.

This commit is contained in:
Christoph Oelckers 2017-04-14 13:48:00 +02:00
parent cd180d29c7
commit 33145610b1

View file

@ -360,13 +360,18 @@ protected:
};
// This is the only method aside from calling CreateNew that should be used for creating DObjects
// to ensure that the Class pointer is always set.
template<typename T, typename... Args>
T* Create(Args&&... args)
{
DObject::nonew nono;
T *object = new(nono) T(std::forward<Args>(args)...);
object->SetClass(RUNTIME_CLASS(T));
assert(object->GetClass() != nullptr); // beware of object that get created before the type system is up.
if (object != nullptr)
{
object->SetClass(RUNTIME_CLASS(T));
assert(object->GetClass() != nullptr); // beware of objects that get created before the type system is up.
}
return object;
}