Add exception handling to various uses of DataStream::read

openmw-35
scrawl 10 years ago
parent 2abc033655
commit fec8cf91f5

@ -25,14 +25,28 @@ void FFmpeg_Decoder::fail(const std::string &msg)
int FFmpeg_Decoder::readPacket(void *user_data, uint8_t *buf, int buf_size)
{
Ogre::DataStreamPtr stream = static_cast<FFmpeg_Decoder*>(user_data)->mDataStream;
return stream->read(buf, buf_size);
try
{
Ogre::DataStreamPtr stream = static_cast<FFmpeg_Decoder*>(user_data)->mDataStream;
return stream->read(buf, buf_size);
}
catch (std::exception& e)
{
return 0;
}
}
int FFmpeg_Decoder::writePacket(void *user_data, uint8_t *buf, int buf_size)
{
Ogre::DataStreamPtr stream = static_cast<FFmpeg_Decoder*>(user_data)->mDataStream;
return stream->write(buf, buf_size);
try
{
Ogre::DataStreamPtr stream = static_cast<FFmpeg_Decoder*>(user_data)->mDataStream;
return stream->write(buf, buf_size);
}
catch (std::exception& e)
{
return 0;
}
}
int64_t FFmpeg_Decoder::seek(void *user_data, int64_t offset, int whence)

@ -123,7 +123,7 @@ std::string ESMReader::getHString()
// Skip the following zero byte
mCtx.leftRec--;
char c;
mEsm->read(&c, 1);
getExact(&c, 1);
return "";
}
@ -186,7 +186,7 @@ void ESMReader::getSubName()
}
// reading the subrecord data anyway.
mEsm->read(mCtx.subName.name, 4);
getExact(mCtx.subName.name, 4);
mCtx.leftRec -= 4;
}
@ -194,7 +194,7 @@ bool ESMReader::isEmptyOrGetName()
{
if (mCtx.leftRec)
{
mEsm->read(mCtx.subName.name, 4);
getExact(mCtx.subName.name, 4);
mCtx.leftRec -= 4;
return false;
}
@ -294,9 +294,16 @@ void ESMReader::getRecHeader(uint32_t &flags)
void ESMReader::getExact(void*x, int size)
{
int t = mEsm->read(x, size);
if (t != size)
fail("Read error");
try
{
int t = mEsm->read(x, size);
if (t != size)
fail("Read error");
}
catch (std::exception& e)
{
fail(std::string("Read error: ") + e.what());
}
}
std::string ESMReader::getString(int size)

@ -175,13 +175,27 @@ void PacketQueue::clear()
int VideoState::OgreResource_Read(void *user_data, uint8_t *buf, int buf_size)
{
Ogre::DataStreamPtr stream = static_cast<VideoState*>(user_data)->stream;
return stream->read(buf, buf_size);
try
{
return stream->read(buf, buf_size);
}
catch (std::exception& e)
{
return 0;
}
}
int VideoState::OgreResource_Write(void *user_data, uint8_t *buf, int buf_size)
{
Ogre::DataStreamPtr stream = static_cast<VideoState*>(user_data)->stream;
return stream->write(buf, buf_size);
try
{
return stream->write(buf, buf_size);
}
catch (std::exception& e)
{
return 0;
}
}
int64_t VideoState::OgreResource_Seek(void *user_data, int64_t offset, int whence)

Loading…
Cancel
Save