Add some checks trying to prevent creation of 0 sized textures.

Saw a crash log with a driver crash in CreateTexture...
This commit is contained in:
Henrik Rydgård 2021-02-13 11:33:15 +01:00
parent d23bef1525
commit c8dfa091fa
2 changed files with 20 additions and 14 deletions

View file

@ -31,6 +31,11 @@ static bool IsDepthStencilFormat(VkFormat format) {
}
bool VulkanTexture::CreateDirect(VkCommandBuffer cmd, VulkanDeviceAllocator *allocator, int w, int h, int numMips, VkFormat format, VkImageLayout initialLayout, VkImageUsageFlags usage, const VkComponentMapping *mapping) {
if (w == 0 || h == 0 || numMips == 0) {
ERROR_LOG(G3D, "Can't create a zero-size VulkanTexture");
return false;
}
Wipe();
width_ = w;

View file

@ -124,25 +124,26 @@ bool ManagedTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, Imag
}
int potentialLevels = std::min(log2i(width[0]), log2i(height[0]));
TextureDesc desc{};
desc.type = TextureType::LINEAR2D;
desc.format = fmt;
desc.width = width[0];
desc.height = height[0];
desc.depth = 1;
desc.mipLevels = generateMips ? potentialLevels : num_levels;
desc.generateMips = generateMips && potentialLevels > num_levels;
desc.tag = name;
for (int i = 0; i < num_levels; i++) {
desc.initData.push_back(image[i]);
if (width[0] > 0 && height[0] > 0) {
TextureDesc desc{};
desc.type = TextureType::LINEAR2D;
desc.format = fmt;
desc.width = width[0];
desc.height = height[0];
desc.depth = 1;
desc.mipLevels = generateMips ? potentialLevels : num_levels;
desc.generateMips = generateMips && potentialLevels > num_levels;
desc.tag = name;
for (int i = 0; i < num_levels; i++) {
desc.initData.push_back(image[i]);
}
texture_ = draw_->CreateTexture(desc);
}
texture_ = draw_->CreateTexture(desc);
for (int i = 0; i < num_levels; i++) {
if (image[i])
free(image[i]);
}
return texture_;
return texture_ != nullptr;
}
bool ManagedTexture::LoadFromFile(const std::string &filename, ImageFileType type, bool generateMips) {