issue #0003070: VRML 2 crashes with corner cases
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
#include "SoFCSelection.h"
|
||||
#include <App/VRMLObject.h>
|
||||
#include <App/Document.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Stream.h>
|
||||
#include <sstream>
|
||||
@@ -96,21 +97,21 @@ std::vector<std::string> ViewProviderVRMLObject::getDisplayModes(void) const
|
||||
template<typename T>
|
||||
void ViewProviderVRMLObject::getResourceFile(SoNode* node, std::list<std::string>& resources)
|
||||
{
|
||||
SoSearchAction sa;
|
||||
sa.setType(T::getClassTypeId());
|
||||
sa.setInterest(SoSearchAction::ALL);
|
||||
sa.setSearchingAll(true);
|
||||
sa.apply(node);
|
||||
const SoPathList & pathlist = sa.getPaths();
|
||||
for (int i = 0; i < pathlist.getLength(); i++ ) {
|
||||
SoFullPath * path = static_cast<SoFullPath *>(pathlist[i]);
|
||||
if (path->getTail()->isOfType(T::getClassTypeId())) {
|
||||
T * tex = static_cast<T*>(path->getTail());
|
||||
for (int j = 0; j < tex->url.getNum(); j++) {
|
||||
this->addResource(tex->url[j], resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
SoSearchAction sa;
|
||||
sa.setType(T::getClassTypeId());
|
||||
sa.setInterest(SoSearchAction::ALL);
|
||||
sa.setSearchingAll(true);
|
||||
sa.apply(node);
|
||||
const SoPathList & pathlist = sa.getPaths();
|
||||
for (int i = 0; i < pathlist.getLength(); i++ ) {
|
||||
SoFullPath * path = static_cast<SoFullPath *>(pathlist[i]);
|
||||
if (path->getTail()->isOfType(T::getClassTypeId())) {
|
||||
T * tex = static_cast<T*>(path->getTail());
|
||||
for (int j = 0; j < tex->url.getNum(); j++) {
|
||||
this->addResource(tex->url[j], resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Gui {
|
||||
@@ -118,92 +119,92 @@ namespace Gui {
|
||||
template<>
|
||||
void ViewProviderVRMLObject::getResourceFile<SoVRMLBackground>(SoNode* node, std::list<std::string>& resources)
|
||||
{
|
||||
SoSearchAction sa;
|
||||
sa.setType(SoVRMLBackground::getClassTypeId());
|
||||
sa.setInterest(SoSearchAction::ALL);
|
||||
sa.setSearchingAll(true);
|
||||
sa.apply(node);
|
||||
const SoPathList & pathlist = sa.getPaths();
|
||||
for (int i = 0; i < pathlist.getLength(); i++ ) {
|
||||
SoFullPath * path = static_cast<SoFullPath *>(pathlist[i]);
|
||||
if (path->getTail()->isOfType(SoVRMLBackground::getClassTypeId())) {
|
||||
SoVRMLBackground * vrml = static_cast<SoVRMLBackground*>(path->getTail());
|
||||
// backUrl
|
||||
for (int j = 0; j < vrml->backUrl.getNum(); j++) {
|
||||
addResource(vrml->backUrl[j], resources);
|
||||
}
|
||||
// bottomUrl
|
||||
for (int j = 0; j < vrml->bottomUrl.getNum(); j++) {
|
||||
addResource(vrml->bottomUrl[j], resources);
|
||||
}
|
||||
// frontUrl
|
||||
for (int j = 0; j < vrml->frontUrl.getNum(); j++) {
|
||||
addResource(vrml->frontUrl[j], resources);
|
||||
}
|
||||
// leftUrl
|
||||
for (int j = 0; j < vrml->leftUrl.getNum(); j++) {
|
||||
addResource(vrml->leftUrl[j], resources);
|
||||
}
|
||||
// rightUrl
|
||||
for (int j = 0; j < vrml->rightUrl.getNum(); j++) {
|
||||
addResource(vrml->rightUrl[j], resources);
|
||||
}
|
||||
// topUrl
|
||||
for (int j = 0; j < vrml->topUrl.getNum(); j++) {
|
||||
addResource(vrml->topUrl[j], resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
SoSearchAction sa;
|
||||
sa.setType(SoVRMLBackground::getClassTypeId());
|
||||
sa.setInterest(SoSearchAction::ALL);
|
||||
sa.setSearchingAll(true);
|
||||
sa.apply(node);
|
||||
const SoPathList & pathlist = sa.getPaths();
|
||||
for (int i = 0; i < pathlist.getLength(); i++ ) {
|
||||
SoFullPath * path = static_cast<SoFullPath *>(pathlist[i]);
|
||||
if (path->getTail()->isOfType(SoVRMLBackground::getClassTypeId())) {
|
||||
SoVRMLBackground * vrml = static_cast<SoVRMLBackground*>(path->getTail());
|
||||
// backUrl
|
||||
for (int j = 0; j < vrml->backUrl.getNum(); j++) {
|
||||
addResource(vrml->backUrl[j], resources);
|
||||
}
|
||||
// bottomUrl
|
||||
for (int j = 0; j < vrml->bottomUrl.getNum(); j++) {
|
||||
addResource(vrml->bottomUrl[j], resources);
|
||||
}
|
||||
// frontUrl
|
||||
for (int j = 0; j < vrml->frontUrl.getNum(); j++) {
|
||||
addResource(vrml->frontUrl[j], resources);
|
||||
}
|
||||
// leftUrl
|
||||
for (int j = 0; j < vrml->leftUrl.getNum(); j++) {
|
||||
addResource(vrml->leftUrl[j], resources);
|
||||
}
|
||||
// rightUrl
|
||||
for (int j = 0; j < vrml->rightUrl.getNum(); j++) {
|
||||
addResource(vrml->rightUrl[j], resources);
|
||||
}
|
||||
// topUrl
|
||||
for (int j = 0; j < vrml->topUrl.getNum(); j++) {
|
||||
addResource(vrml->topUrl[j], resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ViewProviderVRMLObject::addResource(const SbString& url, std::list<std::string>& resources)
|
||||
{
|
||||
SbString found = SoInput::searchForFile(url, SoInput::getDirectories(), SbStringList());
|
||||
Base::FileInfo fi(found.getString());
|
||||
if (fi.exists()) {
|
||||
// add the resource file if not yet listed
|
||||
if (std::find(resources.begin(), resources.end(), found.getString()) == resources.end()) {
|
||||
resources.push_back(found.getString());
|
||||
}
|
||||
}
|
||||
SbString found = SoInput::searchForFile(url, SoInput::getDirectories(), SbStringList());
|
||||
Base::FileInfo fi(found.getString());
|
||||
if (fi.exists()) {
|
||||
// add the resource file if not yet listed
|
||||
if (std::find(resources.begin(), resources.end(), found.getString()) == resources.end()) {
|
||||
resources.push_back(found.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderVRMLObject::getLocalResources(SoNode* node, std::list<std::string>& resources)
|
||||
{
|
||||
// search for SoVRMLInline files
|
||||
SoSearchAction sa;
|
||||
sa.setType(SoVRMLInline::getClassTypeId());
|
||||
sa.setInterest(SoSearchAction::ALL);
|
||||
sa.setSearchingAll(true);
|
||||
sa.apply(node);
|
||||
|
||||
const SoPathList & pathlist = sa.getPaths();
|
||||
for (int i = 0; i < pathlist.getLength(); i++ ) {
|
||||
SoPath * path = pathlist[i];
|
||||
SoVRMLInline * vrml = static_cast<SoVRMLInline*>(path->getTail());
|
||||
const SbString& url = vrml->getFullURLName();
|
||||
if (url.getLength() > 0) {
|
||||
// add the resource file if not yet listed
|
||||
if (std::find(resources.begin(), resources.end(), url.getString()) == resources.end()) {
|
||||
resources.push_back(url.getString());
|
||||
}
|
||||
|
||||
// if the resource file could be loaded check if it references further resources
|
||||
if (vrml->getChildData()) {
|
||||
getLocalResources(vrml->getChildData(), resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search for SoVRMLImageTexture, ... files
|
||||
getResourceFile<SoVRMLImageTexture >(node, resources);
|
||||
getResourceFile<SoVRMLMovieTexture >(node, resources);
|
||||
getResourceFile<SoVRMLScript >(node, resources);
|
||||
getResourceFile<SoVRMLBackground >(node, resources);
|
||||
getResourceFile<SoVRMLAudioClip >(node, resources);
|
||||
getResourceFile<SoVRMLAnchor >(node, resources);
|
||||
sa.setType(SoVRMLInline::getClassTypeId());
|
||||
sa.setInterest(SoSearchAction::ALL);
|
||||
sa.setSearchingAll(true);
|
||||
sa.apply(node);
|
||||
|
||||
const SoPathList & pathlist = sa.getPaths();
|
||||
for (int i = 0; i < pathlist.getLength(); i++ ) {
|
||||
SoPath * path = pathlist[i];
|
||||
SoVRMLInline * vrml = static_cast<SoVRMLInline*>(path->getTail());
|
||||
const SbString& url = vrml->getFullURLName();
|
||||
if (url.getLength() > 0) {
|
||||
// add the resource file if not yet listed
|
||||
if (std::find(resources.begin(), resources.end(), url.getString()) == resources.end()) {
|
||||
resources.push_back(url.getString());
|
||||
}
|
||||
|
||||
// if the resource file could be loaded check if it references further resources
|
||||
if (vrml->getChildData()) {
|
||||
getLocalResources(vrml->getChildData(), resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search for SoVRMLImageTexture, ... files
|
||||
getResourceFile<SoVRMLImageTexture >(node, resources);
|
||||
getResourceFile<SoVRMLMovieTexture >(node, resources);
|
||||
getResourceFile<SoVRMLScript >(node, resources);
|
||||
getResourceFile<SoVRMLBackground >(node, resources);
|
||||
getResourceFile<SoVRMLAudioClip >(node, resources);
|
||||
getResourceFile<SoVRMLAnchor >(node, resources);
|
||||
}
|
||||
|
||||
void ViewProviderVRMLObject::updateData(const App::Property* prop)
|
||||
@@ -231,15 +232,19 @@ void ViewProviderVRMLObject::updateData(const App::Property* prop)
|
||||
SoSeparator * node = SoDB::readAll(&in);
|
||||
|
||||
if (node) {
|
||||
if (!checkRecursion(node)) {
|
||||
Base::Console().Error("The VRML file causes an infinite recursion!\n");
|
||||
return;
|
||||
}
|
||||
pcVRML->addChild(node);
|
||||
|
||||
std::list<std::string> urls;
|
||||
getLocalResources(node, urls);
|
||||
if (!urls.empty() && ivObj->Urls.getSize() == 0) {
|
||||
if (!urls.empty() && ivObj->Urls.getSize() == 0) {
|
||||
std::vector<std::string> res;
|
||||
res.insert(res.end(), urls.begin(), urls.end());
|
||||
ivObj->Urls.setValues(res);
|
||||
}
|
||||
ivObj->Urls.setValues(res);
|
||||
}
|
||||
}
|
||||
SoInput::removeDirectory(filepath.constData());
|
||||
SoInput::removeDirectory(subpath.constData());
|
||||
|
||||
Reference in New Issue
Block a user