mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 23:02:08 +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>
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue