mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-14 18:35:59 +08:00
Remove some assert()
This commit is contained in:
parent
c201efb998
commit
c6817d206b
33
tiny_gltf.h
33
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,
|
||||||
@ -4027,7 +4036,7 @@ static bool ParseExtensionsProperty(ExtensionMap *ret, std::string *err,
|
|||||||
template <typename GltfType>
|
template <typename GltfType>
|
||||||
static bool ParseExtrasAndExtensions(GltfType * target, std::string *err,
|
static bool ParseExtrasAndExtensions(GltfType * target, std::string *err,
|
||||||
const detail::json & o, bool store_json_strings) {
|
const detail::json & o, bool store_json_strings) {
|
||||||
|
|
||||||
ParseExtensionsProperty(&target->extensions, err, o);
|
ParseExtensionsProperty(&target->extensions, err, o);
|
||||||
ParseExtrasProperty(&target->extras, o);
|
ParseExtrasProperty(&target->extras, o);
|
||||||
|
|
||||||
@ -4936,7 +4945,7 @@ static bool ParseNode(Node *node, std::string *err, const detail::json &o,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
node->light = light;
|
node->light = light;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6708,7 +6717,7 @@ static void SerializeExtensionMap(const ExtensionMap &extensions, detail::json &
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeExtras(const Value & extras, detail::json & o) {
|
static void SerializeExtras(const Value & extras, detail::json & o) {
|
||||||
if (extras.Type() != NULL_TYPE)
|
if (extras.Type() != NULL_TYPE)
|
||||||
SerializeValue("extras", extras, o);
|
SerializeValue("extras", extras, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user