Improve null root handling

pull/593/head
Dobrohotov Alexei 4 years ago
parent b10a817f7e
commit 19f0b80983

@ -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));
}
}

@ -121,12 +121,14 @@ osg::ref_ptr<Resource::BulletShape> BulletNifLoader::load(const Nif::File& nif)
mAvoidStaticMesh.reset();
const size_t numRoots = nif.numRoots();
std::vector<Nif::Node*> roots;
std::vector<const Nif::Node*> roots;
for (size_t i = 0; i < numRoots; ++i)
{
Nif::Record* r = nif.getRoot(i);
assert(r != nullptr);
if (Nif::Node* node = dynamic_cast<Nif::Node*>(r))
const Nif::Record* r = nif.getRoot(i);
if (!r)
continue;
const Nif::Node* node = dynamic_cast<const Nif::Node*>(r);
if (node)
roots.emplace_back(node);
}
const std::string filename = nif.getFilename();

@ -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<const Nif::NiSequenceStreamHelper*>(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<const Nif::Node*>(r))
if (!r)
continue;
const Nif::Node* nifNode = dynamic_cast<const Nif::Node*>(r);
if (nifNode)
roots.emplace_back(nifNode);
}
if (roots.empty())

Loading…
Cancel
Save