0

I'm doing Info manager for Dxgi and id like to allocate memory for my message but it writes that problem, any other solution

        HRESULT hr;
        SIZE_T messageLength;
        // get the size of message i in yte
        GFX_THROW_NOINFO(pDxgiInfoQueue->GetMessage(DXGI_DEBUG_ALL, i, nullptr, &messageLength));
        
        auto bytes = std::make_unique<byte[]>(messageLength);

And this is the code after that

    auto pMessage = reinterpret_cast<DXGI_INFO_QUEUE_MESSAGE*>(bytes.get());
    // get the message and push its description into the vector
    GFX_THROW_NOINFO(pDxgiInfoQueue->GetMessage(DXGI_DEBUG_ALL, i, pMessage, &messageLength));
    messages.emplace_back(pMessage->pDescription);
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • What is the `byte` type you are using? Very similar code using `std::byte` does not generate the error you quote. – Adrian Mole Jan 12 '23 at 13:44
  • 1
    please show a [mre] and the full error message text, your code as is works: https://godbolt.org/z/aess36Wc1. Does your compiler/standard library support c++14? – Alan Birtles Jan 12 '23 at 13:46
  • Also, give us the *full* error message - that should include the argument type(s) the compiler thinks you want to use. – Adrian Mole Jan 12 '23 at 13:46

1 Answers1

0

I would suggest using a std::vector in this case

std::vector<byte> bytes(messageLength);

then later

auto pMessage = reinterpret_cast<DXGI_INFO_QUEUE_MESSAGE*>(bytes.data());
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218