Hi,

On Tuesday 19 July 2011, Jan Ciger wrote:
> Guys, could you post which version of OpenVRML is this against? Also
> your platform, please - this code was added, because on my Linux
> everything was working fine, but the Windows/Mac folks were reporting
> problems.
>
> I suspect a change in OpenVRML since then, but need more data to be able
> to confirm that.

Ok, I have completely rechecked with current versions.
openvrml is todays svn. osg is todays 3.0 release branch.

Here, the file:///absolutepathto.wrl just does not work here.
Relative paths or plain absolute paths without the file:// prefix work fine.

I have attached a patch to the vrml loader that might be mostly worthwhile 
anyway.
Most part of the patch is the extended osgnotify info messages when something 
fails which is very helpful if it fails.

The change in behaviour is the use of the plain unix file name that is fed 
into openvrml.

Feel free to use this patch in any way. That is modify to make it portable and 
post upstream ...

Greetings

Mathias

-- 
Dr. Mathias Fröhlich, science + computing ag, Software Solutions
Hagellocher Weg 71-75, D-72070 Tuebingen, Germany
Phone: +49 7071 9457-268, Fax: +49 7071 9457-511
-- 
Vorstand/Board of Management:
Dr. Bernd Finkbeiner, Dr. Roland Niemeier, 
Dr. Arno Steitz, Dr. Ingrid Zech
Vorsitzender des Aufsichtsrats/
Chairman of the Supervisory Board:
Philippe Miltin
Sitz/Registered Office: Tuebingen
Registergericht/Registration Court: Stuttgart
Registernummer/Commercial Register No.: HRB 382196 

Index: src/osgPlugins/vrml/ReaderWriterVRML2.cpp
===================================================================
--- src/osgPlugins/vrml/ReaderWriterVRML2.cpp	(revision 12702)
+++ src/osgPlugins/vrml/ReaderWriterVRML2.cpp	(working copy)
@@ -182,29 +182,37 @@
     // OpenVRML doesn't like backslashes, even on Windows
     std::string unixFileName = osgDB::convertFileNameToUnixStyle(fileName);
 
-#ifdef WIN32
-    if(unixFileName[1] == ':') // absolute path
-    fileName = "file:///" + unixFileName;
-#else
-    if (unixFileName[0] == '/') // absolute path
-        fileName = "file://" + unixFileName;
-#endif
+#ifdef _WIN32
+    if(2 <= unixFileName.size() && unixFileName[1] == ':') // absolute path
+        fileName = "file:///" + unixFileName;
     else
         // relative path
         fileName = unixFileName;
+#else
+    // On unix this appears to work fine this way
+    fileName = unixFileName;
+#endif
 
     std::fstream null;
     resource_fetcher fetcher;
     openvrml::browser *b = new openvrml::browser(fetcher, null, null);
 
     osgDB::ifstream vrml_stream(fileName.c_str());
+    if (!vrml_stream.is_open())
+    {
+        OSG_INFO << "ReaderWriterVRML2: Could not open \"" << fname << "\" expanded to uri " << "\"" << fileName << "\"" << std::endl;
+        return ReadResult::FILE_NOT_FOUND;
+    }
 
     try
     {
         const std::vector< boost::intrusive_ptr< openvrml::node > > & mfn = b->create_vrml_from_stream(vrml_stream);
 
         if(mfn.empty())
+        {
+            OSG_INFO << "ReaderWriterVRML2: OpenVRML library did not return any vrml nodes." << std::endl;
             return ReadResult::FILE_NOT_HANDLED;
+        }
         else
         {
             osg::ref_ptr<osg::MatrixTransform> osg_root = new osg::MatrixTransform(osg::Matrix( 1, 0, 0, 0,
@@ -223,8 +231,16 @@
         }
     }
 
-    catch (openvrml::invalid_vrml) { return ReadResult::FILE_NOT_HANDLED; }
-    catch (std::invalid_argument)  { return ReadResult::FILE_NOT_HANDLED; }
+    catch (const openvrml::invalid_vrml& e)
+    {
+        OSG_INFO << "ReaderWriterVRML2: Invalid VRML in line " << e.line << " at column " << e.column << ": \"" << e.what() << "\"" << std::endl;
+        return ReadResult::FILE_NOT_HANDLED;
+    }
+    catch (const std::invalid_argument& e)
+    {
+        OSG_INFO << "ReaderWriterVRML2: Invalid argument: \"" << e.what() << "\"" << std::endl;
+        return ReadResult::FILE_NOT_HANDLED;
+    }
 }
 
 osgDB::ReaderWriter::WriteResult ReaderWriterVRML2::writeNode(const osg::Node& root,const std::string& filename, const osgDB::ReaderWriter::Options *options) const
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to