A missing bufferview was causing a crash.
parent
de610b8ce9
commit
01b2088dd3
|
@ -289,7 +289,8 @@ Ref<T> LazyDict<T>::Retrieve(unsigned int i) {
|
||||||
|
|
||||||
// Unique ptr prevents memory leak in case of Read throws an exception
|
// Unique ptr prevents memory leak in case of Read throws an exception
|
||||||
auto inst = std::unique_ptr<T>(new T());
|
auto inst = std::unique_ptr<T>(new T());
|
||||||
inst->id = std::string(mDictId) + "_" + to_string(i);
|
// Try to make this human readable so it can be used in error messages.
|
||||||
|
inst->id = std::string(mDictId) + "[" + to_string(i) + "]";
|
||||||
inst->oIndex = i;
|
inst->oIndex = i;
|
||||||
ReadMember(obj, "name", inst->name);
|
ReadMember(obj, "name", inst->name);
|
||||||
inst->Read(obj, mAsset);
|
inst->Read(obj, mAsset);
|
||||||
|
@ -637,15 +638,18 @@ inline void Accessor::Read(Value &obj, Asset &r) {
|
||||||
const char *typestr;
|
const char *typestr;
|
||||||
type = ReadMember(obj, "type", typestr) ? AttribType::FromString(typestr) : AttribType::SCALAR;
|
type = ReadMember(obj, "type", typestr) ? AttribType::FromString(typestr) : AttribType::SCALAR;
|
||||||
|
|
||||||
// Check length
|
if (bufferView)
|
||||||
unsigned long long byteLength = (unsigned long long)GetBytesPerComponent() * (unsigned long long)count;
|
{
|
||||||
if ((byteOffset + byteLength) > bufferView->byteLength || (bufferView->byteOffset + byteOffset + byteLength) > bufferView->buffer->byteLength) {
|
// Check length
|
||||||
const uint8_t val_size = 64;
|
unsigned long long byteLength = (unsigned long long)GetBytesPerComponent() * (unsigned long long)count;
|
||||||
|
if ((byteOffset + byteLength) > bufferView->byteLength || (bufferView->byteOffset + byteOffset + byteLength) > bufferView->buffer->byteLength) {
|
||||||
|
const uint8_t val_size = 64;
|
||||||
|
|
||||||
char val[val_size];
|
char val[val_size];
|
||||||
|
|
||||||
ai_snprintf(val, val_size, "%llu, %llu", (unsigned long long)byteOffset, (unsigned long long)byteLength);
|
ai_snprintf(val, val_size, "%llu, %llu", (unsigned long long)byteOffset, (unsigned long long)byteLength);
|
||||||
throw DeadlyImportError("GLTF: Accessor with offset/length (", val, ") is out of range.");
|
throw DeadlyImportError("GLTF: Accessor with offset/length (", val, ") is out of range.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Value *sparseValue = FindObject(obj, "sparse")) {
|
if (Value *sparseValue = FindObject(obj, "sparse")) {
|
||||||
|
@ -737,13 +741,24 @@ inline void CopyData(size_t count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::string getContextForErrorMessages(const std::string& id, const std::string& name)
|
||||||
|
{
|
||||||
|
std::string context = id;
|
||||||
|
if (!name.empty())
|
||||||
|
{
|
||||||
|
context += " (\"" + name + "\")";
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void Accessor::ExtractData(T *&outData) {
|
void Accessor::ExtractData(T *&outData) {
|
||||||
uint8_t *data = GetPointer();
|
uint8_t *data = GetPointer();
|
||||||
if (!data) {
|
if (!data) {
|
||||||
throw DeadlyImportError("GLTF2: data is nullptr.");
|
throw DeadlyImportError("GLTF2: data is nullptr when extracting data from ", getContextForErrorMessages(id, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t elemSize = GetElementSize();
|
const size_t elemSize = GetElementSize();
|
||||||
|
|
Loading…
Reference in New Issue