mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-15 06:26:01 +08:00
Remove some assert()
This commit is contained in:
parent
c201efb998
commit
c6817d206b
27
tiny_gltf.h
27
tiny_gltf.h
@ -38,7 +38,7 @@
|
|||||||
#define TINY_GLTF_H_
|
#define TINY_GLTF_H_
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cassert>
|
//#include <cassert>
|
||||||
#include <cmath> // std::fabs
|
#include <cmath> // std::fabs
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@ -341,19 +341,28 @@ class Value {
|
|||||||
T &Get();
|
T &Get();
|
||||||
|
|
||||||
// Lookup value from an array
|
// Lookup value from an array
|
||||||
|
// TODO: Deprecate this API
|
||||||
const Value &Get(int idx) const {
|
const Value &Get(int idx) const {
|
||||||
static Value null_value;
|
static Value null_value;
|
||||||
assert(IsArray());
|
if (!IsArray()) {
|
||||||
assert(idx >= 0);
|
return null_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idx < 0) {
|
||||||
|
return null_value;
|
||||||
|
}
|
||||||
return (static_cast<size_t>(idx) < array_value_.size())
|
return (static_cast<size_t>(idx) < array_value_.size())
|
||||||
? array_value_[static_cast<size_t>(idx)]
|
? array_value_[static_cast<size_t>(idx)]
|
||||||
: null_value;
|
: null_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup value from a key-value pair
|
// Lookup value from a key-value pair
|
||||||
|
// TODO: Deprecate this API
|
||||||
const Value &Get(const std::string &key) const {
|
const Value &Get(const std::string &key) const {
|
||||||
static Value null_value;
|
static Value null_value;
|
||||||
assert(IsObject());
|
if (!IsObject()) {
|
||||||
|
return null_value;
|
||||||
|
}
|
||||||
Object::const_iterator it = object_value_.find(key);
|
Object::const_iterator it = object_value_.find(key);
|
||||||
return (it != object_value_.end()) ? it->second : null_value;
|
return (it != object_value_.end()) ? it->second : null_value;
|
||||||
}
|
}
|
||||||
@ -1361,7 +1370,7 @@ class TinyGLTF {
|
|||||||
|
|
||||||
///
|
///
|
||||||
/// Loads glTF ASCII asset from a file.
|
/// Loads glTF ASCII asset from a file.
|
||||||
/// Set warning message to `warn` for example it fails to load asserts.
|
/// Set warning message to `warn` for example it fails to load assets.
|
||||||
/// Returns false and set error string to `err` if there's an error.
|
/// Returns false and set error string to `err` if there's an error.
|
||||||
///
|
///
|
||||||
bool LoadASCIIFromFile(Model *model, std::string *err, std::string *warn,
|
bool LoadASCIIFromFile(Model *model, std::string *err, std::string *warn,
|
||||||
@ -1373,7 +1382,7 @@ class TinyGLTF {
|
|||||||
/// `length` = strlen(str);
|
/// `length` = strlen(str);
|
||||||
/// `base_dir` is a search path of glTF asset(e.g. images). Path Must be an
|
/// `base_dir` is a search path of glTF asset(e.g. images). Path Must be an
|
||||||
/// expanded path (e.g. no tilde(`~`), no environment variables). Set warning
|
/// expanded path (e.g. no tilde(`~`), no environment variables). Set warning
|
||||||
/// message to `warn` for example it fails to load asserts. Returns false and
|
/// message to `warn` for example it fails to load assets. Returns false and
|
||||||
/// set error string to `err` if there's an error.
|
/// set error string to `err` if there's an error.
|
||||||
///
|
///
|
||||||
bool LoadASCIIFromString(Model *model, std::string *err, std::string *warn,
|
bool LoadASCIIFromString(Model *model, std::string *err, std::string *warn,
|
||||||
@ -1383,7 +1392,7 @@ class TinyGLTF {
|
|||||||
|
|
||||||
///
|
///
|
||||||
/// Loads glTF binary asset from a file.
|
/// Loads glTF binary asset from a file.
|
||||||
/// Set warning message to `warn` for example it fails to load asserts.
|
/// Set warning message to `warn` for example it fails to load assets.
|
||||||
/// Returns false and set error string to `err` if there's an error.
|
/// Returns false and set error string to `err` if there's an error.
|
||||||
///
|
///
|
||||||
bool LoadBinaryFromFile(Model *model, std::string *err, std::string *warn,
|
bool LoadBinaryFromFile(Model *model, std::string *err, std::string *warn,
|
||||||
@ -1395,7 +1404,7 @@ class TinyGLTF {
|
|||||||
/// `length` = strlen(str);
|
/// `length` = strlen(str);
|
||||||
/// `base_dir` is a search path of glTF asset(e.g. images). Path Must be an
|
/// `base_dir` is a search path of glTF asset(e.g. images). Path Must be an
|
||||||
/// expanded path (e.g. no tilde(`~`), no environment variables).
|
/// expanded path (e.g. no tilde(`~`), no environment variables).
|
||||||
/// Set warning message to `warn` for example it fails to load asserts.
|
/// Set warning message to `warn` for example it fails to load assets.
|
||||||
/// Returns false and set error string to `err` if there's an error.
|
/// Returns false and set error string to `err` if there's an error.
|
||||||
///
|
///
|
||||||
bool LoadBinaryFromMemory(Model *model, std::string *err, std::string *warn,
|
bool LoadBinaryFromMemory(Model *model, std::string *err, std::string *warn,
|
||||||
@ -1497,7 +1506,7 @@ class TinyGLTF {
|
|||||||
///
|
///
|
||||||
/// Loads glTF asset from string(memory).
|
/// Loads glTF asset from string(memory).
|
||||||
/// `length` = strlen(str);
|
/// `length` = strlen(str);
|
||||||
/// Set warning message to `warn` for example it fails to load asserts
|
/// Set warning message to `warn` for example it fails to load assets
|
||||||
/// Returns false and set error string to `err` if there's an error.
|
/// Returns false and set error string to `err` if there's an error.
|
||||||
///
|
///
|
||||||
bool LoadFromString(Model *model, std::string *err, std::string *warn,
|
bool LoadFromString(Model *model, std::string *err, std::string *warn,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user