Minor blender exception detection bug fix

This commit is contained in:
Jack Andersen 2019-10-12 18:54:07 -10:00
parent 88e68e8aa3
commit 72fabc9329
6 changed files with 60 additions and 50 deletions

2
hecl/extern/athena vendored

@ -1 +1 @@
Subproject commit 42581c922a4574f4f34df134a454effa9f9cc8d0 Subproject commit ee012692ba6981a5889d38e76e717e2cb0216e57

2
hecl/extern/boo vendored

@ -1 +1 @@
Subproject commit 922fcbb3c23677b3ccc53737fd23ada165ccf9f3 Subproject commit 314563614e0e2e2a6f020a423096900e79220119

View File

@ -45,10 +45,10 @@ class HMDLBuffers;
extern logvisor::Module BlenderLog; extern logvisor::Module BlenderLog;
struct PoolSkinIndex { struct PoolSkinIndex {
size_t m_poolSz = 0; std::size_t m_poolSz = 0;
std::unique_ptr<uint32_t[]> m_poolToSkinIndex; std::unique_ptr<uint32_t[]> m_poolToSkinIndex;
void allocate(size_t poolSz) { void allocate(std::size_t poolSz) {
m_poolSz = poolSz; m_poolSz = poolSz;
if (poolSz) if (poolSz)
m_poolToSkinIndex.reset(new uint32_t[poolSz]); m_poolToSkinIndex.reset(new uint32_t[poolSz]);
@ -145,15 +145,15 @@ struct Vector4f {
}; };
struct Matrix3f { struct Matrix3f {
std::array<atVec3f, 3> m; std::array<atVec3f, 3> m;
atVec3f& operator[](size_t idx) { return m[idx]; } atVec3f& operator[](std::size_t idx) { return m[idx]; }
const atVec3f& operator[](size_t idx) const { return m[idx]; } const atVec3f& operator[](std::size_t idx) const { return m[idx]; }
}; };
struct Matrix4f { struct Matrix4f {
std::array<atVec4f, 4> val; std::array<atVec4f, 4> val;
Matrix4f() = default; Matrix4f() = default;
Matrix4f(Connection& conn) { read(conn); } Matrix4f(Connection& conn) { read(conn); }
void read(Connection& conn); void read(Connection& conn);
const atVec4f& operator[](size_t idx) const { return val[idx]; } const atVec4f& operator[](std::size_t idx) const { return val[idx]; }
}; };
struct Index { struct Index {
uint32_t val; uint32_t val;
@ -289,9 +289,9 @@ struct Material {
/** Intermediate mesh representation prepared by blender from a single mesh object */ /** Intermediate mesh representation prepared by blender from a single mesh object */
struct Mesh { struct Mesh {
static constexpr size_t MaxColorLayers = 4; static constexpr std::size_t MaxColorLayers = 4;
static constexpr size_t MaxUVLayers = 8; static constexpr std::size_t MaxUVLayers = 8;
static constexpr size_t MaxSkinEntries = 16; static constexpr std::size_t MaxSkinEntries = 16;
HMDLTopology topology; HMDLTopology topology;
@ -325,10 +325,10 @@ struct Mesh {
bool operator==(const SkinBind& other) const { return vg_idx == other.vg_idx && weight == other.weight; } bool operator==(const SkinBind& other) const { return vg_idx == other.vg_idx && weight == other.weight; }
}; };
std::vector<std::array<SkinBind, MaxSkinEntries>> skins; std::vector<std::array<SkinBind, MaxSkinEntries>> skins;
std::vector<size_t> contiguousSkinVertCounts; std::vector<std::size_t> contiguousSkinVertCounts;
static size_t countSkinBinds(const std::array<SkinBind, MaxSkinEntries>& arr) { static std::size_t countSkinBinds(const std::array<SkinBind, MaxSkinEntries>& arr) {
size_t ret = 0; std::size_t ret = 0;
for (const auto& b : arr) for (const auto& b : arr)
if (b.valid()) if (b.valid())
++ret; ++ret;
@ -553,7 +553,7 @@ struct Armature {
std::vector<Bone> bones; std::vector<Bone> bones;
const Bone* lookupBone(const char* name) const; const Bone* lookupBone(const char* name) const;
const Bone* getParent(const Bone* bone) const; const Bone* getParent(const Bone* bone) const;
const Bone* getChild(const Bone* bone, size_t child) const; const Bone* getChild(const Bone* bone, std::size_t child) const;
const Bone* getRoot() const; const Bone* getRoot() const;
Armature(Connection& conn); Armature(Connection& conn);
}; };
@ -734,8 +734,8 @@ class Connection {
uint32_t _writeStr(const char* str, uint32_t len, int wpipe); uint32_t _writeStr(const char* str, uint32_t len, int wpipe);
uint32_t _writeStr(const char* str, uint32_t len) { return _writeStr(str, len, m_writepipe[1]); } uint32_t _writeStr(const char* str, uint32_t len) { return _writeStr(str, len, m_writepipe[1]); }
uint32_t _writeStr(std::string_view view) { return _writeStr(view.data(), view.size()); } uint32_t _writeStr(std::string_view view) { return _writeStr(view.data(), view.size()); }
size_t _readBuf(void* buf, size_t len); std::size_t _readBuf(void* buf, std::size_t len);
size_t _writeBuf(const void* buf, size_t len); std::size_t _writeBuf(const void* buf, std::size_t len);
std::string _readStdString() { std::string _readStdString() {
uint32_t bufSz; uint32_t bufSz;
_readBuf(&bufSz, 4); _readBuf(&bufSz, 4);
@ -868,14 +868,14 @@ public:
private: private:
friend struct Mesh; friend struct Mesh;
HMDLBuffers(HMDLMeta&& meta, size_t vboSz, const std::vector<atUint32>& iboData, std::vector<Surface>&& surfaces, HMDLBuffers(HMDLMeta&& meta, std::size_t vboSz, const std::vector<atUint32>& iboData, std::vector<Surface>&& surfaces,
const Mesh::SkinBanks& skinBanks); const Mesh::SkinBanks& skinBanks);
public: public:
HMDLMeta m_meta; HMDLMeta m_meta;
size_t m_vboSz; std::size_t m_vboSz;
std::unique_ptr<uint8_t[]> m_vboData; std::unique_ptr<uint8_t[]> m_vboData;
size_t m_iboSz; std::size_t m_iboSz;
std::unique_ptr<uint8_t[]> m_iboData; std::unique_ptr<uint8_t[]> m_iboData;
struct Surface { struct Surface {
@ -895,16 +895,16 @@ public:
namespace std { namespace std {
template <> template <>
struct hash<hecl::blender::Vector2f> { struct hash<hecl::blender::Vector2f> {
size_t operator()(const hecl::blender::Vector2f& val) const noexcept { std::size_t operator()(const hecl::blender::Vector2f& val) const noexcept {
size_t h = std::hash<float>()(val.val.simd[0]); std::size_t h = std::hash<float>()(val.val.simd[0]);
hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[1])); hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[1]));
return h; return h;
} }
}; };
template <> template <>
struct hash<hecl::blender::Vector3f> { struct hash<hecl::blender::Vector3f> {
size_t operator()(const hecl::blender::Vector3f& val) const noexcept { std::size_t operator()(const hecl::blender::Vector3f& val) const noexcept {
size_t h = std::hash<float>()(val.val.simd[0]); std::size_t h = std::hash<float>()(val.val.simd[0]);
hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[1])); hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[1]));
hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[2])); hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[2]));
return h; return h;
@ -912,8 +912,8 @@ struct hash<hecl::blender::Vector3f> {
}; };
template <> template <>
struct hash<hecl::blender::Vector4f> { struct hash<hecl::blender::Vector4f> {
size_t operator()(const hecl::blender::Vector4f& val) const noexcept { std::size_t operator()(const hecl::blender::Vector4f& val) const noexcept {
size_t h = std::hash<float>()(val.val.simd[0]); std::size_t h = std::hash<float>()(val.val.simd[0]);
hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[1])); hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[1]));
hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[2])); hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[2]));
hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[3])); hecl::hash_combine_impl(h, std::hash<float>()(val.val.simd[3]));
@ -922,8 +922,8 @@ struct hash<hecl::blender::Vector4f> {
}; };
template <> template <>
struct hash<array<hecl::blender::Mesh::SkinBind, 16>> { struct hash<array<hecl::blender::Mesh::SkinBind, 16>> {
size_t operator()(const array<hecl::blender::Mesh::SkinBind, 16>& val) const noexcept { std::size_t operator()(const array<hecl::blender::Mesh::SkinBind, 16>& val) const noexcept {
size_t h = 0; std::size_t h = 0;
for (const auto& bind : val) { for (const auto& bind : val) {
if (!bind.valid()) if (!bind.valid())
break; break;

View File

@ -46,6 +46,7 @@ public:
constexpr bool operator!=(uint32_t other) const noexcept { return !operator==(other); } constexpr bool operator!=(uint32_t other) const noexcept { return !operator==(other); }
std::string toString() const { return std::string(std::begin(fcc), std::end(fcc)); } std::string toString() const { return std::string(std::begin(fcc), std::end(fcc)); }
constexpr std::string_view toStringView() const { return std::string_view(fcc, std::size(fcc)); }
constexpr uint32_t toUint32() const noexcept { return num; } constexpr uint32_t toUint32() const noexcept { return num; }
constexpr const char* getChars() const noexcept { return fcc; } constexpr const char* getChars() const noexcept { return fcc; }
constexpr char* getChars() noexcept { return fcc; } constexpr char* getChars() noexcept { return fcc; }
@ -58,10 +59,10 @@ using BigDNA = athena::io::DNA<athena::Endian::Big>;
/** FourCC with DNA read/write */ /** FourCC with DNA read/write */
class DNAFourCC final : public BigDNA, public FourCC { class DNAFourCC final : public BigDNA, public FourCC {
public: public:
DNAFourCC() : FourCC() {} constexpr DNAFourCC() : FourCC() {}
DNAFourCC(const FourCC& other) : FourCC() { num = other.toUint32(); } constexpr DNAFourCC(const FourCC& other) : FourCC() { num = other.toUint32(); }
DNAFourCC(const char* name) : FourCC(name) {} constexpr DNAFourCC(const char* name) : FourCC(name) {}
DNAFourCC(uint32_t n) : FourCC(n) {} constexpr DNAFourCC(uint32_t n) : FourCC(n) {}
AT_DECL_EXPLICIT_DNA_YAML AT_DECL_EXPLICIT_DNA_YAML
}; };
template <> template <>

View File

@ -36,7 +36,7 @@
namespace std { namespace std {
template <> template <>
struct hash<std::pair<uint32_t, uint32_t>> { struct hash<std::pair<uint32_t, uint32_t>> {
size_t operator()(const std::pair<uint32_t, uint32_t>& val) const noexcept { std::size_t operator()(const std::pair<uint32_t, uint32_t>& val) const noexcept {
/* this will potentially truncate the second value if 32-bit size_t, /* this will potentially truncate the second value if 32-bit size_t,
* however, its application here is intended to operate in 16-bit indices */ * however, its application here is intended to operate in 16-bit indices */
return val.first | (val.second << 16); return val.first | (val.second << 16);
@ -86,7 +86,7 @@ static void InstallAddon(const SystemChar* path) {
std::fwrite(HECL_ADDON, 1, HECL_ADDON_SZ, fp.get()); std::fwrite(HECL_ADDON, 1, HECL_ADDON_SZ, fp.get());
} }
static int Read(int fd, void* buf, size_t size) { static int Read(int fd, void* buf, std::size_t size) {
int intrCount = 0; int intrCount = 0;
do { do {
auto ret = read(fd, buf, size); auto ret = read(fd, buf, size);
@ -101,7 +101,7 @@ static int Read(int fd, void* buf, size_t size) {
return -1; return -1;
} }
static int Write(int fd, const void* buf, size_t size) { static int Write(int fd, const void* buf, std::size_t size) {
int intrCount = 0; int intrCount = 0;
do { do {
auto ret = write(fd, buf, size); auto ret = write(fd, buf, size);
@ -116,6 +116,14 @@ static int Write(int fd, const void* buf, size_t size) {
return -1; return -1;
} }
static std::size_t BoundedStrLen(const char* buf, std::size_t maxLen) {
std::size_t ret;
for (ret = 0; ret < maxLen; ++ret)
if (buf[ret] == '\0')
break;
return ret;
}
uint32_t Connection::_readStr(char* buf, uint32_t bufSz) { uint32_t Connection::_readStr(char* buf, uint32_t bufSz) {
uint32_t readLen; uint32_t readLen;
int ret = Read(m_readpipe[0], &readLen, sizeof(readLen)); int ret = Read(m_readpipe[0], &readLen, sizeof(readLen));
@ -138,8 +146,9 @@ uint32_t Connection::_readStr(char* buf, uint32_t bufSz) {
} }
constexpr std::string_view exception_str{"EXCEPTION"}; constexpr std::string_view exception_str{"EXCEPTION"};
if (readLen >= exception_str.size()) { const std::size_t readStrLen = BoundedStrLen(buf, readLen);
if (exception_str.compare(0, exception_str.size(), buf) == 0) { if (readStrLen >= exception_str.size()) {
if (exception_str.compare(0, exception_str.size(), std::string_view(buf, readStrLen)) == 0) {
_blenderDied(); _blenderDied();
return 0; return 0;
} }
@ -168,14 +177,14 @@ uint32_t Connection::_writeStr(const char* buf, uint32_t len, int wpipe) {
return static_cast<uint32_t>(ret); return static_cast<uint32_t>(ret);
} }
size_t Connection::_readBuf(void* buf, size_t len) { std::size_t Connection::_readBuf(void* buf, std::size_t len) {
const auto error = [this] { const auto error = [this] {
_blenderDied(); _blenderDied();
return 0U; return 0U;
}; };
auto* cBuf = static_cast<uint8_t*>(buf); auto* cBuf = static_cast<uint8_t*>(buf);
size_t readLen = 0; std::size_t readLen = 0;
do { do {
const int ret = Read(m_readpipe[0], cBuf, len); const int ret = Read(m_readpipe[0], cBuf, len);
@ -184,8 +193,9 @@ size_t Connection::_readBuf(void* buf, size_t len) {
} }
constexpr std::string_view exception_str{"EXCEPTION"}; constexpr std::string_view exception_str{"EXCEPTION"};
if (len >= exception_str.size()) { const std::size_t readStrLen = BoundedStrLen(static_cast<char*>(buf), len);
if (exception_str.compare(0, exception_str.size(), static_cast<char*>(buf)) == 0) { if (readStrLen >= exception_str.size()) {
if (exception_str.compare(0, exception_str.size(), std::string_view(static_cast<char*>(buf), readStrLen)) == 0) {
_blenderDied(); _blenderDied();
} }
} }
@ -198,14 +208,14 @@ size_t Connection::_readBuf(void* buf, size_t len) {
return readLen; return readLen;
} }
size_t Connection::_writeBuf(const void* buf, size_t len) { std::size_t Connection::_writeBuf(const void* buf, std::size_t len) {
const auto error = [this] { const auto error = [this] {
_blenderDied(); _blenderDied();
return 0U; return 0U;
}; };
const auto* cBuf = static_cast<const uint8_t*>(buf); const auto* cBuf = static_cast<const uint8_t*>(buf);
size_t writeLen = 0; std::size_t writeLen = 0;
do { do {
const int ret = Write(m_writepipe[1], cBuf, len); const int ret = Write(m_writepipe[1], cBuf, len);
@ -925,9 +935,9 @@ Mesh Mesh::getContiguousSkinningVersion() const {
newMesh.norm.clear(); newMesh.norm.clear();
newMesh.contiguousSkinVertCounts.clear(); newMesh.contiguousSkinVertCounts.clear();
newMesh.contiguousSkinVertCounts.reserve(skins.size()); newMesh.contiguousSkinVertCounts.reserve(skins.size());
for (size_t i = 0; i < skins.size(); ++i) { for (std::size_t i = 0; i < skins.size(); ++i) {
std::unordered_map<std::pair<uint32_t, uint32_t>, uint32_t> contigMap; std::unordered_map<std::pair<uint32_t, uint32_t>, uint32_t> contigMap;
size_t vertCount = 0; std::size_t vertCount = 0;
for (Surface& surf : newMesh.surfaces) { for (Surface& surf : newMesh.surfaces) {
for (Surface::Vert& vert : surf.verts) { for (Surface::Vert& vert : surf.verts) {
if (vert.iPos == 0xffffffff) if (vert.iPos == 0xffffffff)
@ -1057,7 +1067,7 @@ uint32_t Mesh::SkinBanks::addSurface(const Mesh& mesh, const Surface& surf, int
continue; continue;
if (!VertInBank(bank.m_skinIdxs, v.iSkin) && !VertInBank(toAdd, v.iSkin)) { if (!VertInBank(bank.m_skinIdxs, v.iSkin) && !VertInBank(toAdd, v.iSkin)) {
toAdd.push_back(v.iSkin); toAdd.push_back(v.iSkin);
if (skinSlotCount > 0 && bank.m_skinIdxs.size() + toAdd.size() > size_t(skinSlotCount)) { if (skinSlotCount > 0 && bank.m_skinIdxs.size() + toAdd.size() > std::size_t(skinSlotCount)) {
toAdd.clear(); toAdd.clear();
done = false; done = false;
break; break;
@ -1192,7 +1202,7 @@ const Bone* Armature::getParent(const Bone* bone) const {
return &bones[bone->parent]; return &bones[bone->parent];
} }
const Bone* Armature::getChild(const Bone* bone, size_t child) const { const Bone* Armature::getChild(const Bone* bone, std::size_t child) const {
if (child >= bone->children.size()) if (child >= bone->children.size())
return nullptr; return nullptr;
int32_t cIdx = bone->children[child]; int32_t cIdx = bone->children[child];
@ -1692,7 +1702,7 @@ void Token::shutdown() {
Token::~Token() { shutdown(); } Token::~Token() { shutdown(); }
HMDLBuffers::HMDLBuffers(HMDLMeta&& meta, size_t vboSz, const std::vector<atUint32>& iboData, HMDLBuffers::HMDLBuffers(HMDLMeta&& meta, std::size_t vboSz, const std::vector<atUint32>& iboData,
std::vector<Surface>&& surfaces, const Mesh::SkinBanks& skinBanks) std::vector<Surface>&& surfaces, const Mesh::SkinBanks& skinBanks)
: m_meta(std::move(meta)) : m_meta(std::move(meta))
, m_vboSz(vboSz) , m_vboSz(vboSz)

View File

@ -269,15 +269,14 @@ static bool RegexSearchLast(const T& str, std::match_results<typename T::const_i
static const hecl::SystemRegex regParsedHash32(_SYS_STR(R"(_([0-9a-fA-F]{8}))"), static const hecl::SystemRegex regParsedHash32(_SYS_STR(R"(_([0-9a-fA-F]{8}))"),
std::regex::ECMAScript | std::regex::optimize); std::regex::ECMAScript | std::regex::optimize);
uint32_t ProjectPath::parsedHash32() const { uint32_t ProjectPath::parsedHash32() const {
{ if (!m_auxInfo.empty()) {
hecl::SystemRegexMatch match; hecl::SystemRegexMatch match;
if (RegexSearchLast(m_auxInfo, match, regParsedHash32)) { if (RegexSearchLast(m_auxInfo, match, regParsedHash32)) {
auto hexStr = match[1].str(); auto hexStr = match[1].str();
if (auto val = hecl::StrToUl(hexStr.c_str(), nullptr, 16)) if (auto val = hecl::StrToUl(hexStr.c_str(), nullptr, 16))
return val; return val;
} }
} } else {
{
hecl::SystemViewRegexMatch match; hecl::SystemViewRegexMatch match;
if (RegexSearchLast(getLastComponent(), match, regParsedHash32)) { if (RegexSearchLast(getLastComponent(), match, regParsedHash32)) {
auto hexStr = match[1].str(); auto hexStr = match[1].str();