Hi Riccardo,

On 27 March 2018 at 17:14, Riccardo Corsi <riccardo.co...@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.
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})
#include <iostream>

#include <osg/Notify>
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>

int main( int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc, argv);


   // get folder and file to use, default to ../osg/Version header file
   std::string dir = "../include/osg/";
   arguments.read("--dir", dir);

   std::string file = "Version";
   arguments.read("--file", file);

   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;

    return 0;
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to