Fix model loading edge case;

This commit is contained in:
bjorn 2020-08-26 04:41:15 -06:00
parent 2ced7c2c16
commit 6c2679e00f
2 changed files with 4 additions and 2 deletions

View File

@ -149,7 +149,7 @@ static jsmntok_t* resolveTexture(const char* json, jsmntok_t* token, ModelMateri
ModelData* lovrModelDataInitGltf(ModelData* model, Blob* source, ModelDataIO* io) {
uint8_t* data = source->data;
gltfHeader* header = (gltfHeader*) data;
bool glb = header->magic == MAGIC_glTF;
bool glb = source->size >= sizeof(gltfHeader) && header->magic == MAGIC_glTF;
const char *json, *binData;
size_t jsonLength;
ptrdiff_t binOffset;

View File

@ -237,7 +237,8 @@ ModelData* lovrModelDataInitObj(ModelData* model, Blob* source, ModelDataIO* io)
}
if (vertexBlob.length == 0 || indexBlob.length == 0) {
return NULL;
model = NULL;
goto finish;
}
model->blobCount = 2;
@ -347,6 +348,7 @@ ModelData* lovrModelDataInitObj(ModelData* model, Blob* source, ModelDataIO* io)
.matrix = true
};
finish:
arr_free(&groups);
arr_free(&textures);
arr_free(&materials);