24 "VulkanBoundsChecking: %s index out of bounds (index: %u, size: %zu)",
39 "VulkanBoundsChecking: %s index out of bounds (index: %zu, size: %zu)",
51 if (frameIndex >= maxFrames) {
53 "VulkanBoundsChecking: Frame index %u exceeds MAX_FRAMES_IN_FLIGHT (%u)",
54 frameIndex, maxFrames);
65 if (imageIndex >= imageCount) {
67 "VulkanBoundsChecking: Image index %u exceeds swapchain image count (%zu)",
68 imageIndex, imageCount);
82 inline T
safeVectorAccess(
const std::vector<T>& vec,
size_t index,
const char* name, T defaultValue) {
83 if (index >= vec.size()) {
85 "VulkanBoundsChecking: Safe access to %s failed (index: %zu, size: %zu)",
86 name, index, vec.size());
100 if (index >= vec.size()) {
102 "VulkanBoundsChecking: Safe pointer access to %s failed (index: %zu, size: %zu)",
103 name, index, vec.size());
116 if (vec.size() != expectedSize) {
118 "VulkanBoundsChecking: %s size mismatch (expected: %zu, actual: %zu)",
119 name, expectedSize, vec.size());
132 if (vec.size() < minSize) {
134 "VulkanBoundsChecking: %s size too small (minimum: %zu, actual: %zu)",
135 name, minSize, vec.size());
145 size_t size1,
const char* name1,
146 size_t size2,
const char* name2,
147 size_t size3,
const char* name3) {
151 if (size1 != size2) {
152 log(LogLevel::WARNING,
153 "VulkanBoundsChecking: %s size (%zu) != %s size (%zu)",
154 name1, size1, name2, size2);
158 if (size1 != size3) {
159 log(LogLevel::WARNING,
160 "VulkanBoundsChecking: %s size (%zu) != %s size (%zu)",
161 name1, size1, name3, size3);
175 for (
size_t i = 0; i < vec.size(); ++i) {
176 if (vec[i] ==
nullptr || vec[i] == VK_NULL_HANDLE) {
178 "VulkanBoundsChecking: %s contains null/invalid handle at index %zu",
195 size_t imageAvailSize,
196 size_t renderFinishedSize,
200 uint32_t expectedSize) {
202 assert(imageAvailSize == expectedSize &&
203 "imageAvailableSemaphores size mismatch with MAX_FRAMES_IN_FLIGHT");
204 assert(renderFinishedSize == expectedSize &&
205 "renderFinishedSemaphores size mismatch with MAX_FRAMES_IN_FLIGHT");
206 assert(fencesSize == expectedSize &&
207 "inFlightFences size mismatch with MAX_FRAMES_IN_FLIGHT");
208 assert(poolsSize == expectedSize &&
209 "commandPools size mismatch with MAX_FRAMES_IN_FLIGHT");
210 assert(buffersSize == expectedSize &&
211 "commandBuffers size mismatch with MAX_FRAMES_IN_FLIGHT");
216 #define VEX_CHECK_FRAME_INDEX(index, maxFrames, funcName) \
218 if (!vex::validateFrameIndex(index, maxFrames)) { \
219 log(LogLevel::ERROR, "%s: Aborting due to invalid frame index", funcName); \
226 #define VEX_CHECK_FRAME_INDEX_BOOL(index, maxFrames, funcName) \
228 if (!vex::validateFrameIndex(index, maxFrames)) { \
229 log(LogLevel::ERROR, "%s: Aborting due to invalid frame index", funcName); \
236 #define VEX_CHECK_IMAGE_INDEX(index, imageCount, funcName) \
238 if (!vex::validateImageIndex(index, imageCount)) { \
239 log(LogLevel::ERROR, "%s: Aborting due to invalid image index", funcName); \
246 #define VEX_CHECK_BOUNDS(index, size, name) \
248 if (!vex::validateVectorBounds(index, size, name)) { \
249 log(LogLevel::ERROR, "Bounds check failed for %s", name); \
256 #define VEX_CHECK_BOUNDS_BOOL(index, size, name) \
258 if (!vex::validateVectorBounds(index, size, name)) { \
259 log(LogLevel::ERROR, "Bounds check failed for %s", name); \
267Now let me create a documentation file explaining the bounds checking system:
bool validateVectorSize(const std::vector< T > &vec, size_t expectedSize, const char *name)
Validates that a vector is properly sized.
T safeVectorAccess(const std::vector< T > &vec, size_t index, const char *name, T defaultValue)
Safely accesses a vector element with bounds checking.
void assertSyncObjectConsistency(size_t imageAvailSize, size_t renderFinishedSize, size_t fencesSize, size_t poolsSize, size_t buffersSize, uint32_t expectedSize)
Asserts that all frame-dependent sync object vectors are properly sized.
T * safeVectorAccessPtr(std::vector< T > &vec, size_t index, const char *name)
Safely accesses a vector element with bounds checking (mutable version).
bool validateFrameIndex(uint32_t frameIndex, uint32_t maxFrames)
Validates that a frame index is valid.
bool validateVectorMinSize(const std::vector< T > &vec, size_t minSize, const char *name)
Validates that a vector has minimum required size.
bool validateImageIndex(uint32_t imageIndex, size_t imageCount)
Validates that an image index is valid.
bool validateNonNullHandles(const std::vector< T > &vec, const char *name)
Validates that all pointers in a vector are non-null.
void VEX_EXPORT log(const char *fmt,...)
Logs a formatted message.
bool validateFrameVectorConsistency(size_t size1, const char *name1, size_t size2, const char *name2, size_t size3, const char *name3)
Validates that multiple frame-dependent vectors have consistent sizes.
bool validateVectorBounds(uint32_t index, size_t size, const char *name)
Validates that an index is within bounds of a vector.