Skip to content

Commit d3936f5

Browse files
Found a super strange bug, also took the time to clean up some code dealing with lifetimes
1 parent 394656d commit d3936f5

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

include/nbl/video/IGPUCommandBuffer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ class NBL_API2 IGPUCommandBuffer :
252252
m_commandList.head = nullptr;
253253
m_commandList.tail = nullptr;
254254

255-
checkForParentPoolReset_impl();
255+
// Example 05 crashes here, with assert in `ucrt` maybe vtable gets lost or something?
256+
// For now commented out because we only have a Vulkan backend and function doesn't do anything.
257+
//checkForParentPoolReset_impl();
256258

257259
return true;
258260
}

include/nbl/video/alloc/CAsyncSingleBufferSubAllocator.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,27 @@ class CAsyncSingleBufferSubAllocator
3434

3535
class DeferredFreeFunctor
3636
{
37-
static constexpr size_t PseudoTupleByteSize = (2u*sizeof(size_type)+sizeof(core::smart_refctd_ptr<core::IReferenceCounted>));
37+
using ref_t = core::smart_refctd_ptr<const core::IReferenceCounted>;
38+
static constexpr size_t PseudoTupleByteSize = 2u*sizeof(size_type)+sizeof(ref_t);
3839
static constexpr size_t AllocatorUnitsPerMetadata = PseudoTupleByteSize/sizeof(typename HostAllocator::value_type);
3940
static_assert((PseudoTupleByteSize%sizeof(typename HostAllocator::value_type)) == 0u, "should be divisible by HostAllocator::value_type");
4041

4142
public:
42-
template<typename T>
43+
template<typename T> requires std::is_base_of_v<core::IReferenceCounted,T>
4344
inline DeferredFreeFunctor(Composed* _composed, size_type numAllocsToFree, const size_type* addrs, const size_type* bytes, const T*const *const objectsToHold)
4445
: composed(_composed), rangeData(nullptr), numAllocs(numAllocsToFree)
4546
{
4647
static_assert(std::is_base_of_v<core::IReferenceCounted,T>);
4748

48-
// TODO : CMemoryPool<RobustGeneralpurposeAllocator> a-la naughty do
49+
// TODO : CMemoryPool<RobustGeneralpurposeAllocator> a-la naughty dog
4950
rangeData = reinterpret_cast<size_type*>(composed->getReservedAllocator().allocate(AllocatorUnitsPerMetadata*numAllocs,sizeof(void*)));
5051
auto out = rangeData;
5152
memcpy(out,addrs,sizeof(size_type)*numAllocs);
5253
out += numAllocs;
5354
memcpy(out,bytes,sizeof(size_type)*numAllocs);
5455
out += numAllocs;
55-
auto* const objHoldIt = reinterpret_cast<core::smart_refctd_ptr<const core::IReferenceCounted>*>(out);
5656
for (size_t i=0u; i<numAllocs; i++)
57-
{
58-
reinterpret_cast<const void**>(out)[i] = nullptr; // clear it first
59-
if (objectsToHold)
60-
objHoldIt[i] = core::smart_refctd_ptr<const core::IReferenceCounted>(objectsToHold[i]);
61-
}
57+
std::construct_at<ref_t>(reinterpret_cast<ref_t*>(out)+i,objectsToHold ? objectsToHold[i]:nullptr);
6258
}
6359
DeferredFreeFunctor(const DeferredFreeFunctor& other) = delete;
6460
inline DeferredFreeFunctor(DeferredFreeFunctor&& other) : composed(nullptr), rangeData(nullptr), numAllocs(0u)
@@ -105,9 +101,7 @@ class CAsyncSingleBufferSubAllocator
105101

106102
inline void operator()()
107103
{
108-
auto* const objHoldIt = reinterpret_cast<core::smart_refctd_ptr<const core::IReferenceCounted>*>(rangeData+numAllocs*2u);
109-
for (size_t i=0u; i<numAllocs; i++)
110-
objHoldIt[i] = nullptr;
104+
std::destroy_n(reinterpret_cast<ref_t*>(rangeData+numAllocs*2u),numAllocs);
111105
#ifdef _NBL_DEBUG
112106
assert(composed && rangeData);
113107
#endif // _NBL_DEBUG

0 commit comments

Comments
 (0)