[osg-users] Bug in osgDB::findFileInDirectory

Robert Osfield robert.osfield at gmail.com
Tue Mar 27 09:35:26 PDT 2018


Hi Riccardo,

On 27 March 2018 at 17:14, Riccardo Corsi <riccardo.corsi at kairos3d.it> wrote:
> I found a bug in osgDB::findFileInDirectory() which does not return the
> expected result on MacOS (and I guess under Linux, but I cannot verify),
> while it works as expected under Windows.
>
> I'm attaching a modified osgversion.cpp which reproduces the issue.

I have just tried your code, with a few mods to see what the return
values are and there is bug in your code (this doens't mean there
isn't a bug on the OSG side, but first we need to get a reliable
test.), I modified the code to:

   std::string fullpath = osgDB::findFileInDirectory(file, dir,
osgDB::CASE_INSENSITIVE);
   bool result = !fullpath.empty();
   OSG_ALWAYS << "Result with findFileInDirectory(): " << result << "
"<<fullpath<<std::endl;

   std::string concatenated = dir + file;
   bool fileExsists = osgDB::fileExists(concatenated);
   OSG_ALWAYS << "Result with fileExists(): " << fileExsists << "
concatenated="<<concatenated<<std::endl;

Note, I've added the output of fullpath and concatenated, the output I get is:

./test --dir ~/OpenSceneGraph/include/osg
Result with findFileInDirectory(): 1
/home/robert/OpenSceneGraph/include/osg/Version
Result with fileExists(): 0
concatenated=/home/robert/OpenSceneGraph/include/osgVersion

Note the include/osgVersion should be include/osg/Version, so it's no
wonder that the fileExists() fails in your test case.

The proper way to join two paths together is to use
osgDB::concatPaths(dir, file);  So I've added some extra code:

   std::string proper_concatenated = osgDB::concatPaths(dir, file);
   bool proper_fileExsists = osgDB::fileExists(proper_concatenated);
   OSG_ALWAYS << "Result with fileExists(): " << proper_fileExsists <<
" proper_fileExsists="<<proper_concatenated<<std::endl;

And the result is:

   Result with fileExists(): 1
proper_fileExsists=/home/robert/OpenSceneGraph/include/osg/Version

Which is correct.

I have cleaned up the .cpp and created a CMakeLists.txt for it, these
are attached, this now just has the relevant code for the test.

Robert.
-------------- next part --------------
cmake_minimum_required(VERSION 2.6)

SET(PROJECT_NAME test)

PROJECT(${PROJECT_NAME})

FIND_PACKAGE(OpenThreads)
FIND_PACKAGE(osg)
FIND_PACKAGE(osgDB)
FIND_PACKAGE(osgUtil)
FIND_PACKAGE(osgGA)
FIND_PACKAGE(osgViewer)

SET(SOURCES
    main.cpp
)

INCLUDE_DIRECTORIES(${OPENTHREADS_INCLUDE_DIR} ${OSG_INCLUDE_DIR})

LINK_DIRECTORIES(${OSG_LIB_DIR})

ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES})

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OSG_LIBRARIES} ${OSGVIEWER_LIBRARIES} ${OSGUTIL_LIBRARIES} ${OSGDB_LIBRARIES} ${OSGGA_LIBRARIES} ${OPENTHREADS_LIBRARIES})
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 844 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20180327/af5e320f/attachment.cpp>


More information about the osg-users mailing list