Print better error messages for failures to save textures to disk

This commit is contained in:
baldurk
2017-06-02 17:59:57 +01:00
parent 922263df83
commit fdf04cae39
5 changed files with 43 additions and 0 deletions
+3
View File
@@ -694,7 +694,10 @@ bool write_dds_to_file(FILE *f, const dds_data &data)
headerDXT10.arraySize = data.slices;
if(headerDXT10.dxgiFormat == DXGI_FORMAT_UNKNOWN)
{
RDCERR("Couldn't convert resource format to DXGI format");
return false;
}
if(data.cubemap)
{
+2
View File
@@ -254,6 +254,8 @@ size_t fwrite(const void *buf, size_t elementSize, size_t count, FILE *f);
bool exists(const char *filename);
std::string ErrorString();
std::string getline(FILE *f);
uint64_t ftell64(FILE *f);
+11
View File
@@ -326,6 +326,17 @@ FILE *fopen(const char *filename, const char *mode)
return ::fopen(filename, mode);
}
std::string ErrorString()
{
int err = errno;
char buf[256] = {0};
strerror_r(err, buf, 256);
return buf;
}
string getline(FILE *f)
{
string ret;
+11
View File
@@ -476,6 +476,17 @@ bool exists(const char *filename)
return (res == 0);
}
std::string ErrorString()
{
int err = errno;
char buf[256] = {0};
strerror_s(buf, err);
return buf;
}
string getline(FILE *f)
{
string ret;
+16
View File
@@ -946,6 +946,7 @@ bool ReplayController::SaveTexture(const TextureSave &saveData, const char *path
if(!f)
{
success = false;
RDCERR("Couldn't write to path %s, error: %s", path, FileIO::ErrorString().c_str());
}
else
{
@@ -969,6 +970,9 @@ bool ReplayController::SaveTexture(const TextureSave &saveData, const char *path
int ret = stbi_write_bmp_to_func(fileWriteFunc, (void *)f, td.width, td.height, numComps,
subdata[0]);
success = (ret != 0);
if(!success)
RDCERR("stbi_write_bmp_to_func failed: %d", ret);
}
else if(sd.destType == FileType::PNG)
{
@@ -979,6 +983,9 @@ bool ReplayController::SaveTexture(const TextureSave &saveData, const char *path
int ret = stbi_write_png_to_func(fileWriteFunc, (void *)f, td.width, td.height, numComps,
subdata[0], rowPitch);
success = (ret != 0);
if(!success)
RDCERR("stbi_write_png_to_func failed: %d", ret);
}
else if(sd.destType == FileType::TGA)
{
@@ -989,6 +996,9 @@ bool ReplayController::SaveTexture(const TextureSave &saveData, const char *path
int ret = stbi_write_tga_to_func(fileWriteFunc, (void *)f, td.width, td.height, numComps,
subdata[0]);
success = (ret != 0);
if(!success)
RDCERR("stbi_write_tga_to_func failed: %d", ret);
}
else if(sd.destType == FileType::JPG)
{
@@ -1005,6 +1015,9 @@ bool ReplayController::SaveTexture(const TextureSave &saveData, const char *path
success = jpge::compress_image_to_jpeg_file_in_memory(jpgdst, len, td.width, td.height,
numComps, subdata[0], p);
if(!success)
RDCERR("jpge::compress_image_to_jpeg_file_in_memory failed");
if(success)
fwrite(jpgdst, 1, len, f);
@@ -1144,6 +1157,9 @@ bool ReplayController::SaveTexture(const TextureSave &saveData, const char *path
{
int ret = stbi_write_hdr_to_func(fileWriteFunc, (void *)f, td.width, td.height, 4, fldata);
success = (ret != 0);
if(!success)
RDCERR("stbi_write_hdr_to_func failed: %d", ret);
}
else if(sd.destType == FileType::EXR)
{