Fixed love.audio.newSource, love.sound.newSoundData, and love.sound.newDecoder crashing when given a nonexistant filepath

This commit is contained in:
Alex Szpakowski
2013-04-19 16:00:36 -03:00
parent 426ca03315
commit a477223629
+4 -16
View File
@@ -79,35 +79,23 @@ int w_newSoundData(lua_State *L)
int w_newDecoder(lua_State *L) int w_newDecoder(lua_State *L)
{ {
// Convert to File, if necessary. // Convert to FileData, if necessary.
if (lua_isstring(L, 1)) if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T))
luax_convobj(L, 1, "filesystem", "newFile"); luax_convobj(L, 1, "filesystem", "newFileData");
love::filesystem::FileData *data; love::filesystem::FileData *data = luax_checktype<love::filesystem::FileData>(L, 1, "FileData", FILESYSTEM_FILE_DATA_T);
if (luax_istype(L, 1, FILESYSTEM_FILE_T))
{
love::filesystem::File *file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
data = file->read();
}
else
{
data = luax_checktype<love::filesystem::FileData>(L, 1, "FileData", FILESYSTEM_FILE_DATA_T);
data->retain();
}
int bufferSize = luaL_optint(L, 2, Decoder::DEFAULT_BUFFER_SIZE); int bufferSize = luaL_optint(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
try try
{ {
Decoder *t = instance->newDecoder(data, bufferSize); Decoder *t = instance->newDecoder(data, bufferSize);
data->release();
if (t == 0) if (t == 0)
return luaL_error(L, "Extension \"%s\" not supported.", data->getExtension().c_str()); return luaL_error(L, "Extension \"%s\" not supported.", data->getExtension().c_str());
luax_newtype(L, "Decoder", SOUND_DECODER_T, (void *)t); luax_newtype(L, "Decoder", SOUND_DECODER_T, (void *)t);
} }
catch(love::Exception &e) catch(love::Exception &e)
{ {
data->release();
return luaL_error(L, e.what()); return luaL_error(L, e.what());
} }