From 19f0b80983a46d08f0d84981b55d1f608b4fd606 Mon Sep 17 00:00:00 2001 From: Dobrohotov Alexei Date: Wed, 5 May 2021 02:26:32 +0300 Subject: [PATCH] Improve null root handling --- components/nif/niffile.cpp | 2 +- components/nifbullet/bulletnifloader.cpp | 10 ++++++---- components/nifosg/nifloader.cpp | 8 +++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index 864a388e8..08301ce47 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -322,7 +322,7 @@ void NIFFile::parse(Files::IStreamPtr stream) else { roots[i] = nullptr; - warn("Null Root found"); + warn("Root " + std::to_string(i + 1) + " does not point to a record: index " + std::to_string(idx)); } } diff --git a/components/nifbullet/bulletnifloader.cpp b/components/nifbullet/bulletnifloader.cpp index 72c740af3..6ae175939 100644 --- a/components/nifbullet/bulletnifloader.cpp +++ b/components/nifbullet/bulletnifloader.cpp @@ -121,12 +121,14 @@ osg::ref_ptr BulletNifLoader::load(const Nif::File& nif) mAvoidStaticMesh.reset(); const size_t numRoots = nif.numRoots(); - std::vector roots; + std::vector roots; for (size_t i = 0; i < numRoots; ++i) { - Nif::Record* r = nif.getRoot(i); - assert(r != nullptr); - if (Nif::Node* node = dynamic_cast(r)) + const Nif::Record* r = nif.getRoot(i); + if (!r) + continue; + const Nif::Node* node = dynamic_cast(r); + if (node) roots.emplace_back(node); } const std::string filename = nif.getFilename(); diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 49d52074a..f7d6fd3ed 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -254,8 +254,7 @@ namespace NifOsg for (size_t i = 0; i < numRoots; ++i) { const Nif::Record *r = nif->getRoot(i); - assert(r != nullptr); - if (r->recType == Nif::RC_NiSequenceStreamHelper) + if (r && r->recType == Nif::RC_NiSequenceStreamHelper) { seq = static_cast(r); break; @@ -312,7 +311,10 @@ namespace NifOsg for (size_t i = 0; i < numRoots; ++i) { const Nif::Record* r = nif->getRoot(i); - if (const Nif::Node* nifNode = dynamic_cast(r)) + if (!r) + continue; + const Nif::Node* nifNode = dynamic_cast(r); + if (nifNode) roots.emplace_back(nifNode); } if (roots.empty())