Skip to content

Commit dbdfab5

Browse files
committed
Algorithm: check type before casting
The if statement used to assume that if `mem->type() == memory::Type::eImage` then it was safe to assume that the memory object is an instance of `kp::Image`. However, any subclass of `kp::Memory` could implement the virtual `type()` method to return `memory::Type::eImage`, so this is an invalid assumption. This commit fixes the issue by only casting if the memory object actually is an instance of `kp::Memory`
1 parent b888179 commit dbdfab5

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

src/OpAlgoDispatch.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ OpAlgoDispatch::record(const vk::CommandBuffer& commandBuffer)
2525

2626
// For images the image layout needs to be set to eGeneral before using
2727
// it for imageLoad/imageStore in a shader.
28-
if (mem->type() == Memory::Type::eImage) {
29-
std::shared_ptr<Image> image = std::static_pointer_cast<Image>(mem);
30-
28+
std::shared_ptr<Image> image = std::dynamic_pointer_cast<Image>(mem);
29+
if (image) {
3130
image->recordPrimaryImageBarrier(
3231
commandBuffer,
3332
vk::AccessFlagBits::eTransferWrite,

0 commit comments

Comments
 (0)