From 33145610b1c3a7f1f1572127fd11faac06c9407b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 14 Apr 2017 13:48:00 +0200 Subject: [PATCH] - let's better add a null check to Create<> in case allocation or construction fails. Although unlikely it's not impossible. --- src/dobject.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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; }