OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Bug in osgDB::findFileInDirectory


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Riccardo Corsi
Guest





PostPosted: Tue Mar 27, 2018 4:19 pm    Post subject:
Bug in osgDB::findFileInDirectory
Reply with quote

Hi Robert and all,


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.


Tested with:
osg 3.6.0-rc2
Win10
MacOS 10.13


Thank you,
riccardo

------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12148

PostPosted: Tue Mar 27, 2018 4:40 pm    Post subject:
Bug in osgDB::findFileInDirectory
Reply with quote

Hi Riccardo,

On 27 March 2018 at 17:14, Riccardo Corsi <> wrote:
Quote:
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.



------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12148

PostPosted: Tue Mar 27, 2018 4:43 pm    Post subject:
Bug in osgDB::findFileInDirectory
Reply with quote

I have just run the test case with a file with the wrong case to see
what would happen, the results look 100% correct:

$ ./test --dir ~/OpenSceneGraph/include/osg --file version
Result with findFileInDirectory(): 1
/home/robert/OpenSceneGraph/include/osg/Version
Result with fileExists(): 0
concatenated=/home/robert/OpenSceneGraph/include/osgversion
Result with fileExists(): 0
proper_fileExsists=/home/robert/OpenSceneGraph/include/osg/version

This test was run under Linux, so at least on the Linux side things
are working correctly. I have to defer to others to test under OSX.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Riccardo Corsi
Guest





PostPosted: Tue Mar 27, 2018 6:40 pm    Post subject:
Bug in osgDB::findFileInDirectory
Reply with quote

Hi Robert,


thanks for the tests. 
You're right I was not concatenating the paths correctly, 
but the concatenation was ok in the default case,
as the directory path contains a final slash.


Now I've realised THAT is the case when the issue comes up:
if you use a directory path which has the final slash, 
findFileInDirectory() fails to find the full path.
Remove the trailing slash and everything works fine.


This happens (at least on OSX) even if you run the example you sent me back without arguments.


I'm re-attaching your example with the concatenation done the right way as you suggested.


Thanks,
Riccardo



On Tue, Mar 27, 2018 at 6:38 PM, Robert Osfield < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
I have just run the test case with a file with the wrong case to see
what would happen, the results look 100% correct:

$ ./test --dir ~/OpenSceneGraph/include/osg  --file version
Result with findFileInDirectory(): 1
/home/robert/OpenSceneGraph/include/osg/Version
Result with fileExists(): 0
concatenated=/home/robert/OpenSceneGraph/include/osgversion
Result with fileExists(): 0
proper_fileExsists=/home/robert/OpenSceneGraph/include/osg/version

This test was run under Linux, so at least on the Linux side things
are working correctly.  I have to defer to others to test under OSX.

Robert.
_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12148

PostPosted: Tue Mar 27, 2018 6:47 pm    Post subject:
Bug in osgDB::findFileInDirectory
Reply with quote

Hi Ricardo,

I have just tried with and wihtout the trailing slash and these are
the results I get under Linux,

./test --dir ~/OpenSceneGraph/include/osg --file version
Result with findFileInDirectory(): 1
/home/robert/OpenSceneGraph/include/osg/Version

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

Which confirms your suggestion that the trailing slash isn't handled
by findFileInDirectory().

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12148

PostPosted: Wed Mar 28, 2018 10:55 am    Post subject:
Bug in osgDB::findFileInDirectory
Reply with quote

Hi Ricardo,

On 27 March 2018 at 19:42, Robert Osfield <> wrote:
Quote:
./test --dir ~/OpenSceneGraph/include/osg/ --file version
Result with findFileInDirectory(): 0
Result with fileExists(): 0
concatenated=/home/robert/OpenSceneGraph/include/osg/version

Which confirms your suggestion that the trailing slash isn't handled
by findFileInDirectory().

I have checked in a catch for users passing in directories with a
trailing / or \. This fix is checked into OSG master and the 3.6
branch.

Robert


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Riccardo Corsi
Guest





PostPosted: Wed Mar 28, 2018 12:52 pm    Post subject:
Bug in osgDB::findFileInDirectory
Reply with quote

​Thanks Robert​

Riccardo Corsi  sw engineering & co-founder
Kairos3D srl  Via Agostino da Montefeltro 2, 10134 Torino Italy

T +390113157111  M +393288522785
Check out our ground-breaking 3D CAD-to-VR toolchain: www.kairos3d.it




















On Wed, Mar 28, 2018 at 12:50 PM, Robert Osfield < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi Ricardo,

On 27 March 2018 at 19:42, Robert Osfield < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
./test --dir ~/OpenSceneGraph/include/osg/ --file version
Result with findFileInDirectory(): 0
Result with fileExists(): 0
concatenated=/home/robert/OpenSceneGraph/include/osg/version

Which confirms your suggestion that the trailing slash isn't handled
by findFileInDirectory().

I have checked in a catch for users passing in directories with a
trailing / or .  This fix is checked into OSG master and the 3.6
branch.

Robert
_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts osgDB::OutputStream write array optim... Farshid Lashkari Submission 2 Thu Sep 20, 2018 11:17 pm View latest post
No new posts Load OSG trimesh to ODE: Read Vertice... TKoller General 2 Fri Jul 20, 2018 3:06 pm View latest post
No new posts osgDB XmlParser and localization Trajce Nikolov NICK General 8 Mon Jul 09, 2018 10:41 am View latest post
No new posts osgDB::readRefNodeFiles() crashes wit... peter_k General 4 Fri Jun 08, 2018 9:18 am View latest post
No new posts Opening .ico image files with osgDB::... ceranco General 1 Wed Mar 07, 2018 7:41 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP