From 8df894924c671458e73b9dd087f2b958b7303973 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 8 Oct 2001 15:54:16 +0000 Subject: [PATCH] Fixed a recently introduced crash in the flt plugin which was happen when a std::string was be be set with NULL char*. Also added support for stripping the filename from its original path, inside the osgDB::findFile function. --- src/osgDB/FileUtils.cpp | 13 ++++++++++++- src/osgPlugins/flt/FltFile.cpp | 6 +++--- src/osgPlugins/flt/Input.cpp | 8 ++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index 13a57db0a..098208145 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -150,7 +150,18 @@ static char *findFileInPath( const char *_file, const char * filePath ) char *osgDB::findFile( const char *file ) { - return findFileInPath( file, s_filePath ); + if (!file) return NULL; + + char* newFileName = findFileInPath( file, s_filePath ); + if (newFileName) return newFileName; + + + // need to check here to see if file has a path on it. + + // now strip the file of an previous path if one exists. + std::string simpleFileName = getSimpleFileName(file); + newFileName = findFileInPath( simpleFileName.c_str(), s_filePath ); + return newFileName; } /* diff --git a/src/osgPlugins/flt/FltFile.cpp b/src/osgPlugins/flt/FltFile.cpp index 5a1271819..8b8eab8bd 100644 --- a/src/osgPlugins/flt/FltFile.cpp +++ b/src/osgPlugins/flt/FltFile.cpp @@ -91,9 +91,9 @@ Record* FltFile::readFile(const std::string& fileName) if (!fin.open(fileName)) { // ok havn't found file, resort to using findFile... - std::string newFileName = osgDB::findFile(fileName.c_str()); - - if (newFileName.empty()) return NULL; + char* newFileName = osgDB::findFile(fileName.c_str()); + + if (!newFileName) return NULL; if (!fin.open(newFileName)) return NULL; } diff --git a/src/osgPlugins/flt/Input.cpp b/src/osgPlugins/flt/Input.cpp index 0a2ab5b36..4b70490b2 100644 --- a/src/osgPlugins/flt/Input.cpp +++ b/src/osgPlugins/flt/Input.cpp @@ -67,10 +67,10 @@ bool FileInput::open(const std::string& fileName) if (_file == NULL) { // ok havn't found file, resort to using findFile... - std::string newFileName = osgDB::findFile(fileName.c_str()); - if (newFileName.empty()) return false; - - _file=::fopen( fileName.c_str(), "rb"); + char* newFileName = osgDB::findFile(fileName.c_str()); + + if (!newFileName) return false; + _file=::fopen( newFileName, "rb"); if (_file == NULL) return false; } _eof = false;