D3D12: Add bounds check to GetBackBuffer and update unit tests

- Add assert() bounds check to GetBackBuffer() to catch invalid indices
- Include <cassert> in D3D12SwapChain.cpp
- Update test_swap_chain.cpp to use reference return type
- Mark InvalidIndex test as DISABLED (assert aborts on invalid index)
- Update get-back-buffer.md documentation
This commit is contained in:
2026-03-20 18:35:00 +08:00
parent 460a2477c3
commit 26fe3cd835
3 changed files with 27 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
#include "XCEngine/RHI/D3D12/D3D12SwapChain.h"
#include <cassert>
namespace XCEngine {
namespace RHI {
@@ -82,10 +83,12 @@ uint32_t D3D12SwapChain::GetCurrentBackBufferIndex() const {
}
D3D12Texture& D3D12SwapChain::GetBackBuffer(uint32_t index) {
assert(index < m_backBuffers.size() && "BackBuffer index out of range");
return m_backBuffers[index];
}
const D3D12Texture& D3D12SwapChain::GetBackBuffer(uint32_t index) const {
assert(index < m_backBuffers.size() && "BackBuffer index out of range");
return m_backBuffers[index];
}