Skip to content

Commit

Permalink
corechecks: Prevent null ptr access for GetSwapchainImages
Browse files Browse the repository at this point in the history
Validation could croak if this two-part query was only called by
the application to retreive the count but not the images.

Change-Id: Iee9ad53bfbd59c6f34054c8ab48161037b1db5ef
  • Loading branch information
mark-lunarg committed Jun 25, 2020
1 parent 76ddcca commit ed01d8a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions layers/core_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11131,9 +11131,12 @@ bool CoreChecks::ValidateAcquireNextImage(VkDevice device, const CommandVersion
auto physical_device_state = GetPhysicalDeviceState();
// TODO: this is technically wrong on many levels, but requires massive cleanup
if (physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called) {
const uint32_t acquired_images =
static_cast<uint32_t>(std::count_if(swapchain_data->images.begin(), swapchain_data->images.end(),
[=](SWAPCHAIN_IMAGE image) { return GetImageState(image.image)->acquired; }));
const uint32_t acquired_images = static_cast<uint32_t>(
std::count_if(swapchain_data->images.begin(), swapchain_data->images.end(), [=](SWAPCHAIN_IMAGE image) {
auto const state = GetImageState(image.image);
return (state && state->acquired);
}));

const uint32_t swapchain_image_count = static_cast<uint32_t>(swapchain_data->images.size());
const auto min_image_count = physical_device_state->surfaceCapabilities.minImageCount;
const bool too_many_already_acquired = acquired_images > swapchain_image_count - min_image_count;
Expand Down

0 comments on commit ed01d8a

Please sign in to comment.