mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2025-04-24 04:53:28 -04:00
Improved reader/writer error handling.
This commit is contained in:
parent
d53b27d353
commit
016bfc4290
11 changed files with 63 additions and 52 deletions
examples
13-stencil
14-shadowvolumes
16-shadowmaps
common
src
tools
|
@ -682,7 +682,7 @@ struct Mesh
|
|||
#define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0)
|
||||
|
||||
bx::CrtFileReader reader;
|
||||
reader.open(_filePath);
|
||||
bx::open(&reader, _filePath);
|
||||
|
||||
Group group;
|
||||
|
||||
|
@ -763,7 +763,7 @@ struct Mesh
|
|||
}
|
||||
}
|
||||
|
||||
reader.close();
|
||||
bx::close(&reader);
|
||||
}
|
||||
|
||||
void unload()
|
||||
|
|
|
@ -1030,7 +1030,7 @@ struct Mesh
|
|||
#define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0)
|
||||
|
||||
bx::CrtFileReader reader;
|
||||
reader.open(_filePath);
|
||||
bx::open(&reader, _filePath);
|
||||
|
||||
Group group;
|
||||
|
||||
|
@ -1114,7 +1114,7 @@ struct Mesh
|
|||
}
|
||||
}
|
||||
|
||||
reader.close();
|
||||
bx::close(&reader);
|
||||
|
||||
for (GroupArray::iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
|
||||
{
|
||||
|
|
|
@ -891,7 +891,7 @@ struct Mesh
|
|||
#define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0)
|
||||
|
||||
bx::CrtFileReader reader;
|
||||
reader.open(_filePath);
|
||||
bx::open(&reader, _filePath);
|
||||
|
||||
Group group;
|
||||
|
||||
|
@ -971,7 +971,7 @@ struct Mesh
|
|||
}
|
||||
}
|
||||
|
||||
reader.close();
|
||||
bx::close(&reader);
|
||||
}
|
||||
|
||||
void unload()
|
||||
|
|
|
@ -26,7 +26,7 @@ struct AviWriter
|
|||
|
||||
bool open(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _fps, bool _yflip)
|
||||
{
|
||||
if (0 != m_writer->open(_filePath) )
|
||||
if (!bx::open(m_writer, _filePath) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ struct AviWriter
|
|||
m_numFrames = 0;
|
||||
m_width = _width;
|
||||
m_height = _height;
|
||||
|
||||
|
||||
// Bgfx returns _yflip true for OpenGL since bottom left corner is 0, 0. In D3D top left corner
|
||||
// is 0, 0. DIB expect OpenGL style coordinates, so this is inverted logic for AVI writer.
|
||||
m_yflip = !_yflip;
|
||||
|
@ -163,7 +163,7 @@ struct AviWriter
|
|||
m_writer->seek(m_lengthOffset, bx::Whence::Begin);
|
||||
bx::write(m_writer, m_numFrames);
|
||||
|
||||
m_writer->close();
|
||||
bx::close(m_writer);
|
||||
|
||||
delete [] m_frame;
|
||||
m_frame = NULL;
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace stl = tinystl;
|
|||
|
||||
void* load(bx::FileReaderI* _reader, bx::AllocatorI* _allocator, const char* _filePath, uint32_t* _size)
|
||||
{
|
||||
if (0 == bx::open(_reader, _filePath) )
|
||||
if (bx::open(_reader, _filePath) )
|
||||
{
|
||||
uint32_t size = (uint32_t)bx::getSize(_reader);
|
||||
void* data = BX_ALLOC(_allocator, size);
|
||||
|
@ -45,6 +45,7 @@ void* load(bx::FileReaderI* _reader, bx::AllocatorI* _allocator, const char* _fi
|
|||
{
|
||||
*_size = 0;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -60,7 +61,7 @@ void unload(void* _ptr)
|
|||
|
||||
static const bgfx::Memory* loadMem(bx::FileReaderI* _reader, const char* _filePath)
|
||||
{
|
||||
if (0 == bx::open(_reader, _filePath) )
|
||||
if (bx::open(_reader, _filePath) )
|
||||
{
|
||||
uint32_t size = (uint32_t)bx::getSize(_reader);
|
||||
const bgfx::Memory* mem = bgfx::alloc(size+1);
|
||||
|
@ -76,7 +77,7 @@ static const bgfx::Memory* loadMem(bx::FileReaderI* _reader, const char* _filePa
|
|||
|
||||
static void* loadMem(bx::FileReaderI* _reader, bx::AllocatorI* _allocator, const char* _filePath, uint32_t* _size)
|
||||
{
|
||||
if (0 == bx::open(_reader, _filePath) )
|
||||
if (bx::open(_reader, _filePath) )
|
||||
{
|
||||
uint32_t size = (uint32_t)bx::getSize(_reader);
|
||||
void* data = BX_ALLOC(_allocator, size);
|
||||
|
@ -596,10 +597,14 @@ Mesh* meshLoad(bx::ReaderSeekerI* _reader)
|
|||
Mesh* meshLoad(const char* _filePath)
|
||||
{
|
||||
bx::FileReaderI* reader = entry::getFileReader();
|
||||
bx::open(reader, _filePath);
|
||||
Mesh* mesh = meshLoad(reader);
|
||||
bx::close(reader);
|
||||
return mesh;
|
||||
if (bx::open(reader, _filePath) )
|
||||
{
|
||||
Mesh* mesh = meshLoad(reader);
|
||||
bx::close(reader);
|
||||
return mesh;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void meshUnload(Mesh* _mesh)
|
||||
|
|
|
@ -426,7 +426,7 @@ namespace entry
|
|||
setWindowSize(defaultWindow, m_width, m_height, true);
|
||||
|
||||
bx::FileReaderI* reader = getFileReader();
|
||||
if (0 == bx::open(reader, "gamecontrollerdb.txt") )
|
||||
if (bx::open(reader, "gamecontrollerdb.txt") )
|
||||
{
|
||||
bx::AllocatorI* allocator = getAllocator();
|
||||
uint32_t size = (uint32_t)bx::getSize(reader);
|
||||
|
|
|
@ -112,10 +112,10 @@ namespace bgfx
|
|||
strcat(filePath, ".tga");
|
||||
|
||||
bx::CrtFileWriter writer;
|
||||
if (0 == writer.open(filePath) )
|
||||
if (bx::open(&writer, filePath) )
|
||||
{
|
||||
imageWriteTga(&writer, _width, _height, _pitch, _data, false, _yflip);
|
||||
writer.close();
|
||||
bx::close(&writer);
|
||||
}
|
||||
#endif // BX_CONFIG_CRT_FILE_READER_WRITER
|
||||
}
|
||||
|
|
|
@ -811,7 +811,7 @@ int main(int _argc, const char* _argv[])
|
|||
PrimitiveArray primitives;
|
||||
|
||||
bx::CrtFileWriter writer;
|
||||
if (0 != writer.open(outFilePath) )
|
||||
if (bx::open(&writer, outFilePath) )
|
||||
{
|
||||
printf("Unable to open output file '%s'.", outFilePath);
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -1000,8 +1000,8 @@ int main(int _argc, const char* _argv[])
|
|||
);
|
||||
}
|
||||
|
||||
printf("size: %d\n", uint32_t(writer.seek() ) );
|
||||
writer.close();
|
||||
printf("size: %d\n", uint32_t(bx::seek(&writer) ) );
|
||||
bx::close(&writer);
|
||||
|
||||
delete [] indexData;
|
||||
delete [] vertexData;
|
||||
|
|
|
@ -158,13 +158,13 @@ namespace bgfx
|
|||
{
|
||||
}
|
||||
|
||||
virtual int32_t close() BX_OVERRIDE
|
||||
virtual void close() BX_OVERRIDE
|
||||
{
|
||||
generate();
|
||||
return bx::CrtFileWriter::close();
|
||||
}
|
||||
|
||||
virtual int32_t write(const void* _data, int32_t _size) BX_OVERRIDE
|
||||
virtual int32_t write(const void* _data, int32_t _size, bx::Error*) BX_OVERRIDE
|
||||
{
|
||||
const char* data = (const char*)_data;
|
||||
m_buffer.insert(m_buffer.end(), data, data+_size);
|
||||
|
@ -174,9 +174,9 @@ namespace bgfx
|
|||
private:
|
||||
void generate()
|
||||
{
|
||||
#define HEX_DUMP_WIDTH 16
|
||||
#define HEX_DUMP_SPACE_WIDTH 96
|
||||
#define HEX_DUMP_FORMAT "%-" BX_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "." BX_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "s"
|
||||
#define HEX_DUMP_WIDTH 16
|
||||
#define HEX_DUMP_SPACE_WIDTH 96
|
||||
#define HEX_DUMP_FORMAT "%-" BX_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "." BX_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "s"
|
||||
const uint8_t* data = &m_buffer[0];
|
||||
uint32_t size = (uint32_t)m_buffer.size();
|
||||
|
||||
|
@ -214,9 +214,9 @@ namespace bgfx
|
|||
}
|
||||
|
||||
outf("};\n");
|
||||
#undef HEX_DUMP_WIDTH
|
||||
#undef HEX_DUMP_SPACE_WIDTH
|
||||
#undef HEX_DUMP_FORMAT
|
||||
#undef HEX_DUMP_WIDTH
|
||||
#undef HEX_DUMP_SPACE_WIDTH
|
||||
#undef HEX_DUMP_FORMAT
|
||||
}
|
||||
|
||||
int32_t outf(const char* _format, ...)
|
||||
|
@ -234,7 +234,8 @@ namespace bgfx
|
|||
len = bx::vsnprintf(out, len, _format, argList);
|
||||
}
|
||||
|
||||
int32_t size = bx::CrtFileWriter::write(out, len);
|
||||
bx::Error err;
|
||||
int32_t size = bx::CrtFileWriter::write(out, len, &err);
|
||||
|
||||
va_end(argList);
|
||||
|
||||
|
@ -351,10 +352,10 @@ namespace bgfx
|
|||
void writeFile(const char* _filePath, const void* _data, int32_t _size)
|
||||
{
|
||||
bx::CrtFileWriter out;
|
||||
if (0 == out.open(_filePath) )
|
||||
if (bx::open(&out, _filePath) )
|
||||
{
|
||||
out.write(_data, _size);
|
||||
out.close();
|
||||
bx::write(&out, _data, _size);
|
||||
bx::close(&out);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1102,7 +1103,7 @@ namespace bgfx
|
|||
writer = new bx::CrtFileWriter;
|
||||
}
|
||||
|
||||
if (0 != writer->open(outFilePath) )
|
||||
if (!bx::open(writer, outFilePath) )
|
||||
{
|
||||
fprintf(stderr, "Unable to open output file '%s'.", outFilePath);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1140,7 +1141,7 @@ namespace bgfx
|
|||
compiled = compileHLSLShader(cmdLine, d3d, input, writer);
|
||||
}
|
||||
|
||||
writer->close();
|
||||
bx::close(writer);
|
||||
delete writer;
|
||||
}
|
||||
else if ('c' == shaderType) // Compute
|
||||
|
@ -1235,14 +1236,14 @@ namespace bgfx
|
|||
{
|
||||
bx::CrtFileWriter writer;
|
||||
|
||||
if (0 != writer.open(outFilePath) )
|
||||
if (!bx::open(&writer, outFilePath) )
|
||||
{
|
||||
fprintf(stderr, "Unable to open output file '%s'.", outFilePath);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
writer.write(preprocessor.m_preprocessed.c_str(), (int32_t)preprocessor.m_preprocessed.size() );
|
||||
writer.close();
|
||||
bx::write(&writer, preprocessor.m_preprocessed.c_str(), (int32_t)preprocessor.m_preprocessed.size() );
|
||||
bx::close(&writer);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -1259,7 +1260,7 @@ namespace bgfx
|
|||
writer = new bx::CrtFileWriter;
|
||||
}
|
||||
|
||||
if (0 != writer->open(outFilePath) )
|
||||
if (!bx::open(writer, outFilePath) )
|
||||
{
|
||||
fprintf(stderr, "Unable to open output file '%s'.", outFilePath);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1301,7 +1302,7 @@ namespace bgfx
|
|||
compiled = compileHLSLShader(cmdLine, d3d, preprocessor.m_preprocessed, writer);
|
||||
}
|
||||
|
||||
writer->close();
|
||||
bx::close(writer);
|
||||
delete writer;
|
||||
}
|
||||
|
||||
|
@ -1312,10 +1313,10 @@ namespace bgfx
|
|||
std::string ofp = outFilePath;
|
||||
ofp += ".d";
|
||||
bx::CrtFileWriter writer;
|
||||
if (0 == writer.open(ofp.c_str() ) )
|
||||
if (bx::open(&writer, ofp.c_str() ) )
|
||||
{
|
||||
writef(&writer, "%s : %s\n", outFilePath, preprocessor.m_depends.c_str() );
|
||||
writer.close();
|
||||
bx::close(&writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1642,7 +1643,7 @@ namespace bgfx
|
|||
{
|
||||
bx::CrtFileWriter writer;
|
||||
|
||||
if (0 != writer.open(outFilePath) )
|
||||
if (!bx::open(&writer, outFilePath) )
|
||||
{
|
||||
fprintf(stderr, "Unable to open output file '%s'.", outFilePath);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1659,8 +1660,8 @@ namespace bgfx
|
|||
);
|
||||
}
|
||||
}
|
||||
writer.write(preprocessor.m_preprocessed.c_str(), (int32_t)preprocessor.m_preprocessed.size() );
|
||||
writer.close();
|
||||
bx::write(&writer, preprocessor.m_preprocessed.c_str(), (int32_t)preprocessor.m_preprocessed.size() );
|
||||
bx::close(&writer);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -1677,7 +1678,7 @@ namespace bgfx
|
|||
writer = new bx::CrtFileWriter;
|
||||
}
|
||||
|
||||
if (0 != writer->open(outFilePath) )
|
||||
if (!bx::open(writer, outFilePath) )
|
||||
{
|
||||
fprintf(stderr, "Unable to open output file '%s'.", outFilePath);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1796,7 +1797,7 @@ namespace bgfx
|
|||
);
|
||||
}
|
||||
|
||||
writer->close();
|
||||
bx::close(writer);
|
||||
delete writer;
|
||||
}
|
||||
|
||||
|
@ -1807,10 +1808,10 @@ namespace bgfx
|
|||
std::string ofp = outFilePath;
|
||||
ofp += ".d";
|
||||
bx::CrtFileWriter writer;
|
||||
if (0 == writer.open(ofp.c_str() ) )
|
||||
if (bx::open(&writer, ofp.c_str() ) )
|
||||
{
|
||||
writef(&writer, "%s : %s\n", outFilePath, preprocessor.m_depends.c_str() );
|
||||
writer.close();
|
||||
bx::close(&writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
#ifndef SHADERC_H_HEADER_GUARD
|
||||
#define SHADERC_H_HEADER_GUARD
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
extern bool g_verbose;
|
||||
}
|
||||
|
||||
#define _BX_TRACE(_format, ...) \
|
||||
BX_MACRO_BLOCK_BEGIN \
|
||||
if (bgfx::g_verbose) \
|
||||
|
|
|
@ -380,7 +380,7 @@ int main(int _argc, const char* _argv[])
|
|||
BX_UNUSED(sdf, edge);
|
||||
|
||||
bx::CrtFileReader reader;
|
||||
if (0 != bx::open(&reader, inputFileName) )
|
||||
if (!bx::open(&reader, inputFileName) )
|
||||
{
|
||||
help("Failed to open input file.");
|
||||
return EXIT_FAILURE;
|
||||
|
@ -546,7 +546,7 @@ int main(int _argc, const char* _argv[])
|
|||
if (NULL != output)
|
||||
{
|
||||
bx::CrtFileWriter writer;
|
||||
if (0 == bx::open(&writer, outputFileName) )
|
||||
if (!bx::open(&writer, outputFileName) )
|
||||
{
|
||||
if (NULL != bx::stristr(outputFileName, ".ktx") )
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue