mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-11 07:12:02 +00:00
- 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:
parent
cd180d29c7
commit
33145610b1
1 changed files with 7 additions and 2 deletions
|
@ -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>
|
template<typename T, typename... Args>
|
||||||
T* Create(Args&&... args)
|
T* Create(Args&&... args)
|
||||||
{
|
{
|
||||||
DObject::nonew nono;
|
DObject::nonew nono;
|
||||||
T *object = new(nono) T(std::forward<Args>(args)...);
|
T *object = new(nono) T(std::forward<Args>(args)...);
|
||||||
object->SetClass(RUNTIME_CLASS(T));
|
if (object != nullptr)
|
||||||
assert(object->GetClass() != nullptr); // beware of object that get created before the type system is up.
|
{
|
||||||
|
object->SetClass(RUNTIME_CLASS(T));
|
||||||
|
assert(object->GetClass() != nullptr); // beware of objects that get created before the type system is up.
|
||||||
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue