[osg-users] problem with osgUtil::IntersectVisitor and osg::LineSegment

3 views
Skip to first unread message

Olivier Martinaud

unread,
May 12, 2010, 9:32:37 AM5/12/10
to osg-...@lists.openscenegraph.org
Hi,

I'm having some trouble implementing an intersection detection method. I have a model of a building and I'd like to get the coordinates of the intersection points between the model and a ray. I wrote the following code from osg samples online.

osg::LineSegment *ls = new osg::LineSegment(osg::Vec3d(-5,-5,-5),osg::Vec3d(5,5,5));
osgUtil::IntersectVisitor *iv = new osgUtil::IntersectVisitor();
iv->addLineSegment(ls);
iv->apply(*m_node);
std::cout << iv->getNumHits(ls) << " intersection points (hits)." << std::endl; //result = 6
osgUtil::IntersectVisitor::HitList& hitlist = iv->getHitList(ls);
std::cout << "size : " << hitlist.size() << std::endl;
//std::vector<osgUtil::Hit>::iterator itr = hitlist.begin();
hitlist[0].getWorldIntersectPoint(); //causes unhandled exception...


When I execute the code I have this error : unhandled exception at 0x100042aa in OSGDefaultProject.exe : 0xC0000005: access violation when reading 0xfeeeff36.
The problem comes from the last line of the code (getWorldIntersectionPoint()). What's weird is that the iv finds 6 points of intersection, so the algorithm seems to work fine. But the size of my hitlist is abnormally large : it says more than 4 billion !


Thank you!

Cheers,
Olivier

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=27798#27798





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

--
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To post to this group, send email to osg-...@googlegroups.com.
To unsubscribe from this group, send email to osg-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/osg-users?hl=en.

Martin Naylor

unread,
May 12, 2010, 12:15:35 PM5/12/10
to osg-...@lists.openscenegraph.org
Hi Oliver,
Are mixing debug and release libraries?

Regards

Martin.

Martin Naylor

unread,
May 12, 2010, 12:17:47 PM5/12/10
to OpenSceneGraph Users
Sorry, Are you mixing debug and release libraries from OSG?
Check you are linking with either all release or all debug.

Martin

Olivier Martinaud

unread,
May 13, 2010, 7:53:00 AM5/13/10
to osg-...@lists.openscenegraph.org
Hi,

Thank you for your answer.

Indeed, I installed both libraries, debug and release. I always compile my code in release mode (it compiles in debug mode but I don't know why the exe doesn't work then). I'll check on monday if both libraries are correctly and separately installed.
Do you think it could cause the problem I have ?



Cheers,
Olivier

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=27856#27856

Martin Naylor

unread,
May 13, 2010, 12:01:27 PM5/13/10
to osg-...@lists.openscenegraph.org
Hi,
Yes Windows doesn't like that or certain parts of it, such as anything that
uses memory allocation.
http://stackoverflow.com/questions/1227653/linking-against-library-in-releas
e-and-exe-in-debug-crashes-in-visual-studio
Have a look at the above.
Of course it could be 1001 other things, but I guess this is the first place
to start.
Check your linker settings and make sure that you are linking against the
correct versions. I did something the other day and linked my release
version again osgd.lib instead of osg.lib and my release version was
crashing.
Also if you post the stack trace it may help find the problem?

-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of Olivier
Martinaud
Sent: 13 May 2010 12:53
To: osg-...@lists.openscenegraph.org
Subject: Re: [osg-users] problem with osgUtil::IntersectVisitor and
osg::LineSegment

Olivier Martinaud

unread,
May 17, 2010, 3:44:22 AM5/17/10
to osg-...@lists.openscenegraph.org
Hello,

I checked the installation of osg. I was not mixing debug and release. But to be sure I uninstalled debug. However I still have the same probem as before. I copied the stack trace if it helps. Do you have any idea ?

osg65-osg.dll!100042aa()
[Les frames ci-dessous sont peut-être incorrects et/ou manquants, aucun symbole chargé pour osg65-osg.dll]
osg65-osgUtil.dll!0048ad2c()
> OSGDefaultProject.exe!PickHandler::coordinates3D(int mouseX=264839480, int mouseY=509, int tailleFenetre=750, double angleVue=2.6388121119329419e-308, double k1=2.6388121119329419e-308, double k2=2.6388121119329419e-308, double k3=2.6388121119329419e-308, double k4=2.6388121119329419e-308, double k5=2.6388121119329419e-308) Ligne 88 C++
OSGDefaultProject.exe!PickHandler::handle(const osgGA::GUIEventAdapter & ea=, osgGA::GUIActionAdapter & aa=) Ligne 33 C++
osg65-osgGA.dll!0042854e()
osg65-osgGA.dll!00421981()
osg65-osgGA.dll!004219cc()
osg65-osgViewer.dll!005b0727()
ntdll.dll!7c91df5a()
ntdll.dll!7c928b23()
ntdll.dll!7c922d78()
msvcr90.dll!785436c5()
msvcr90.dll!785438b3()
msvcr90.dll!785427b4()
OSGDefaultProject.exe!pre_cpp_init() Ligne 326 + 0x27 octets C
msvcr90.dll!78542201()
OSGDefaultProject.exe!__tmainCRTStartup() Ligne 582 + 0x17 octets C
kernel32.dll!7c816fe7()


Thank you,
Regards,
Olivier

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=27921#27921

Martin Naylor

unread,
May 17, 2010, 11:20:08 AM5/17/10
to osg-...@lists.openscenegraph.org
Hi Oliver,

Sorry to hear it wasn’t as simple...
It could be a bug, but normally someone else would 'pipe up' and say that was fixed :)
Does look like a problem with pickhandler, can you post some source code to recreate the problem?
Have you tried the examples and do the work ok?

Also you may want to provide some more details, such as compiler version, version of OS, OSG version in use (prebuilt or compiled from source).
You may also want to try and compile the code against the latest SVN if you are using pre-built DLL's, see if that makes a difference.

It looks like something is being referenced that has a NULL pointer, but I am still learning C++ and will be forever ;)


Martin.

Olivier Martinaud

unread,
May 17, 2010, 1:08:45 PM5/17/10
to osg-...@lists.openscenegraph.org
Hello Martin,


I'm using osg version 2.8.3 with visual C++ express, and my os is windows xp. I also tried the basic examples I could find on tutorials and on the osg website but I still have the same problem :(. I guess it comes from my configuration.
I used this tutorial to install osg : http://dwightdesign.com/2009/05/installing-openscenegraph-280/.
I used the prebuilt version of osg.

Everything I tried on osg worked perfectly except for this function (I also tried polytope intersector, height above terrain... but I got the same error).

You're right it looks like the program is allocating all the memory to the hitlist (the size is over 4 billion). However it looks like the apply method works : I've fot a number of intersections but I just can't have access to the intersection points coordinates.

The code is as follows. m_node points to a model I loaded. The model works fine (it's basically a set of (a lot of) points joined by panels).

osg::LineSegment *ls = new
osg::LineSegment(osg::Vec3d(-5,-5,-5),osg::Vec3d(5,5,5));
osgUtil::IntersectVisitor *iv = new osgUtil::IntersectVisitor();
iv->addLineSegment(ls);
iv->apply(*m_node);
std::cout << iv->getNumHits(ls) << " intersection points (hits)." <<
std::endl; //result = 6
osgUtil::IntersectVisitor::HitList& hitlist = iv->getHitList(ls);
std::cout << "size : " << hitlist.size() << std::endl;
//std::vector<osgUtil::Hit>::iterator itr = hitlist.begin();
hitlist[0].getWorldIntersectPoint(); //causes unhandled exception...



Thanks for your help,

Olivier

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=27950#27950

Martin Naylor

unread,
May 17, 2010, 1:49:06 PM5/17/10
to osg-...@lists.openscenegraph.org
Hi Oliver,
Mmmm isn't IntersectVisitor Depreciated, not sure what version that was?
Try IntersectionVisitor instead?
http://www.openscenegraph.org/projects/osg/wiki/Support/Tutorials/Intersecti
ons

Maybe Robert can advise :) ?


Martin.





-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of Olivier
Martinaud
Sent: 17 May 2010 18:09
To: osg-...@lists.openscenegraph.org
Subject: Re: [osg-users] problem with osgUtil::IntersectVisitor and
osg::LineSegment

Olivier Martinaud

unread,
May 18, 2010, 2:36:44 AM5/18/10
to osg-...@lists.openscenegraph.org
Hi Martin,



Actually I had tried IntersectionVisitor before. I had the same problem, which is why I switched to IntersectVisitor.


Olivier

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=27956#27956

Robert Osfield

unread,
May 18, 2010, 4:02:56 AM5/18/10
to osg-...@lists.openscenegraph.org
Hi Olivier,

On Tue, May 18, 2010 at 7:36 AM, Olivier Martinaud
<olivier....@thalesgroup.com> wrote:
> Actually I had tried IntersectionVisitor before. I had the same problem, which is why I switched to IntersectVisitor.

IntersectVisitor is deprecated and is only kept for backwards compatibility.

The fact that both are crashing for you and neither of these classes
don't crash for thousands of other developers that use them day in day
out suggests to me either:

1) Corrupted build for some reason
2) Corrupted data for some reason.

I'm not a windows programmer so can't comment on the build side. If
you have a chance try out a build on an easier OS to get things
building reliably such as Linux, VS throws it's own complications in
developing C++ applications that haunt all VS users.

As for the data, if you can test osgpick example against the standard
OpenSceneGraph-Data models that everyone else has access to then you
can at least check to see if might be a corrupted data issue.

Robert.

Jean-Sébastien Guay

unread,
May 18, 2010, 7:36:22 AM5/18/10
to osg-...@lists.openscenegraph.org
Bonjour Olivier,

> Actually I had tried IntersectionVisitor before. I had the same problem, which is why I switched to IntersectVisitor.

You really need to send us a complete code example that reproduces your
problem. That means one source file that contains a main() and which we
can compile standalone to see if it works for us, and how we can make it
work.

Someone asked you before in this thread, but your answer was ambiguous:
does the osgpick example work for you? Or does it crash?

The fact your code is crashing on iterating over an stl container
returned from OSG really points to you mixing release and debug. I know
you checked already, but check again. If your app is being compiled in
release, it needs to link to only release libs. If it's being compiled
in debug, it needs to link to only debug libs.

You said earlier in the thread that you link to only release libs, but
is your app also being compiled in release, and against the /MD
(Multi-threaded DLL) runtime? You can keep the debug libs installed (in
fact you won't be able to debug even your own code if you don't) but you
need to make sure your project and the libs it links to match in this
regard. If you're not sure, send us the whole thing : code and Visual
Studio project files.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/

Peter Kilpatrick

unread,
May 18, 2010, 8:05:54 AM5/18/10
to osg-...@lists.openscenegraph.org
Hello Oliver,

You say you are using osg version 2.8.3 and osg binaries.

The only Windows binaries for 2.8.3 I could find on openscenegraph.org are
the following:

http://www.openscenegraph.org/downloads/stable_releases/OpenSceneGraph-2.8.3/binaries/Windows/VisualStudio8/

They are for Visual C++ version 8.

The stack trace that you provide mentions msvcr90.dll. This is the runtime
dll for Visual C++ version 9.

If you are using Visual C++ version 9 then you need to use osg binaries for
Visual C++ version 9.

Regards,
Peter

----- Original Message -----
From: "Olivier Martinaud" <olivier....@thalesgroup.com>
To: <osg-...@lists.openscenegraph.org>
Sent: Monday, May 17, 2010 7:08 PM
Subject: Re: [osg-users] problem with osgUtil::IntersectVisitor
andosg::LineSegment


--------------------------------------------------------------------
Olivier

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=27921#27921



--
This message has been scanned for viruses and
dangerous content by Pinpoint, and is
believed to be clean.

Olivier Martinaud

unread,
May 18, 2010, 8:21:09 AM5/18/10
to osg-...@lists.openscenegraph.org
Hi everybody,


Finally, I decided to reinstall osg using the sources. I took the osg 2.8.3 sources and I compiled them using my version of visual studio. Now everything works perfectly ! Looks like I didn't have the good binaries.

Thank you all for your help !

Cheers,
Olivier

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=27973#27973

Jean-Sébastien Guay

unread,
May 18, 2010, 8:38:44 AM5/18/10
to osg-...@lists.openscenegraph.org
Bonjour Olivier,

> Finally, I decided to reinstall osg using the sources. I took the osg 2.8.3 sources and I compiled them using my version of visual studio. Now everything works perfectly !

Good to know you got it solved.

> Looks like I didn't have the good binaries.

Yes, I think Peter hit the nail on the head. When using Visual Studio
it's really important to make sure everything matches correctly... It
can be a pain, and everyone wonders what MS was thinking of when they
made the design and implementation decisions that led to this, but it's
just something we have to live with if we want to use this tool.

I added a note to the downloads page that the Visual Studio version
needs to match between the OSG libraries and the app they're linked to.
Hopefully that will make it clearer for others in the future.

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/
Reply all
Reply to author
Forward
0 new messages