Skip to content

Commit 279ca31

Browse files
fix the bug in deref not checking for invalid handle and the block tracking trying to insert on a simple lookup
Then fix the CFrontendIR bugs
1 parent ed0766d commit 279ca31

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

include/nbl/asset/material_compiler3/CFrontendIR.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,7 @@ class CFrontendIR final : public CNodePool
773773
retval += "\\n";
774774
retval += std::string_view(reinterpret_cast<const char*>(debug->data().data()),debug->data().size()-1);
775775
}
776-
// TODO: static and dynamic casts for handles
777-
if (const auto* expr=getObjectPool().deref<const IExprNode>({{.value=handle.value}}); expr)
776+
if (const auto* expr=dynamic_cast<const IExprNode*>(node); expr)
778777
retval += expr->getLabelSuffix();
779778
retval += "\"]";
780779
return retval;

include/nbl/asset/material_compiler3/CNodePool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CNodePool : public core::IReferenceCounted
5252

5353
static inline uint32_t calc_size(const void* data, const uint32_t size)
5454
{
55-
return sizeof(CDebugInfo)+size;
55+
return core::alignUp(sizeof(CDebugInfo)+size,alignof(CDebugInfo));
5656
}
5757
static inline uint32_t calc_size(const std::string_view& view)
5858
{

include/nbl/core/alloc/SimpleBlockBasedAllocator.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ class SimpleBlockBasedAllocator<AddressAllocator,HandleValue> final : protected
366366
template<typename T> requires (!std::is_const_v<T>)
367367
inline T* deref(typed_pointer_type<T> p)
368368
{
369-
return reinterpret_cast<T*>(std::launder(getBlock(p)->data(base_t::m_blockCreationParams)+getOffsetInBlock(p)));
369+
if (p)
370+
return reinterpret_cast<T*>(std::launder(getBlock(p)->data(base_t::m_blockCreationParams)+getOffsetInBlock(p)));
371+
return nullptr;
370372
}
371373
template<typename T>
372374
inline const T* deref(typed_pointer_type<T> p) const
@@ -440,7 +442,7 @@ class SimpleBlockBasedAllocator<AddressAllocator,HandleValue> final : protected
440442

441443
private:
442444
inline HandleValue getOffsetInBlock(const typed_pointer_type<const void> h) const {return h.value&m_loAddrMask;}
443-
inline block_t* getBlock(const typed_pointer_type<const void> h) {return m_blocks[getBlockIndex(h)];}
445+
inline block_t* getBlock(const typed_pointer_type<const void> h) {return m_blocks.find(getBlockIndex(h))->second;}
444446

445447
inline HandleValue getBlockIndex(const typed_pointer_type<const void> h) const {return h.value>>m_blockSizeLog2;}
446448

0 commit comments

Comments
 (0)