Pool<T>::newItem leaves trivially copy-constructible types uninitialized
jlaumon opened this issue · comments
I have a trivially copy-constructible struct:
struct MeshInstanceData
{
QuatPosScale mTransform = QuatPosScale::identity();
Float4 mColor = Float4(1.0f);
};
and if I create a Pool and do:
auto data = MeshInstanceData();
mMeshInstances.newItem<u32>(data);
the item in the pool is uninitialized (since the placement new isn't called).
plywood/repos/plywood/src/runtime/ply-runtime/container/Pool.h
Lines 378 to 390 in bb78ab5
Is the trivially constructible check there to avoid zero initialization? Maybe we could check if args are void? (that's a bit outside my template comfort zone 😀).
(Happy new year! 😬)
Hi Jeremy,
Happy new year to you too. I don't think there was a good reason for the std::is_trivially_constructible<>
check or for any other possible check at this point for this matter. It was probably a mistake, so I removed it. Fix has been submit. Thanks for reporting this.
Jeff
You might want to remove the one in delItem
item too then :)
Cheers!
Yea, I guess that one isn't accomplishing much, is it? I do like to use those type traits around a loop though. I imagine it makes things easier for the compiler in certain build configs. (I'm pretty sure I've seen the compiler fail to optimize away an empty loop in the past.)