KhronosGroup / OpenXR-Tutorials

OpenXR Tutorials
https://www.openxr-tutorial.com/
Apache License 2.0
84 stars 15 forks source link

Crash when spawning cube on Chapter 4. #134

Closed mariosubspace closed 1 month ago

mariosubspace commented 1 month ago

Chapter 4 says to set up the CameraConstants Uniform Buffer as such (in CreateResources()):

size_t numberOfCuboids = 64 + 2 + 2;
m_uniformBuffer_Camera = m_graphicsAPI->CreateBuffer({GraphicsAPI::BufferCreateInfo::Type::UNIFORM, 0, sizeof(CameraConstants) * numberOfCuboids, nullptr});

In RenderCuboid() we set the offset to the buffer for that cube as such:

size_t offsetCameraUB = sizeof(CameraConstants) * renderCuboidIndex;
/* ... */
m_graphicsAPI->SetBufferData(m_uniformBuffer_Camera, offsetCameraUB, sizeof(CameraConstants), &cameraConstants);
m_graphicsAPI->SetDescriptor({0, m_uniformBuffer_Camera, GraphicsAPI::DescriptorInfo::Type::BUFFER, GraphicsAPI::DescriptorInfo::Stage::VERTEX, false, offsetCameraUB, sizeof(CameraConstants)});

When spawning a cube this makes it index out of bounds of the buffer.

Suggested fix: Allocate the CameraConstants buffer for size 1, set the offsets to 0 in the other calls, and remove the renderCuboidIndex. We update the buffer for each cube anyway.

rbessems commented 1 month ago

please have a look at the updated code (release 1.0.6 and up) it should fix the crash.

mariosubspace commented 1 month ago

Works for me in a build, Quest 2 + OpenGL ES. No crash and I can see the blocks being reused when it hits max. Closing this issue. Thanks for the quick response!

Btw, I noticed a separate minor issue you may want to check out. When both controllers are active, a block spawns simultaneously for both controllers when pressing the A button.

rbessems commented 1 month ago

Thanks for the report, I'll check it out.