diff --git a/src/dobject.h b/src/dobject.h index 55a05c9552..ee2bfb5af1 100644 --- a/src/dobject.h +++ b/src/dobject.h @@ -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 T* Create(Args&&... args) { DObject::nonew nono; T *object = new(nono) T(std::forward(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; }