Discussion:
[osg-users] Crash when using LineSegmentIntersector
Sam Brkopac
2018-08-02 22:04:09 UTC
Permalink
Hi All,

I have a custom plugin that loads mesh data and then also loads the walkable flag information that is associated with that node. When doing a LineSegmentIntersector to pick the node in the scene everything works perfectly well - until I apply the visitor and append the geometry with the walkable faces. Once the visitor has completed and the user goes to click in the scene, I get a crash. I've managed to create a small example that reproduces the crash.

The stack trace seems to indicate that when the IntersectionVisitor attempts to call Geode::getDrawable() it returns a null drawable. Please note that I do see the proper geometry drawing when the visitor is applied.

https://gist.github.com/sbrkopac/45b4e9d7d35a979e7e0dd7eebbd2a061

Thanks, Sam

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74459#74459
Robert Osfield
2018-08-03 08:38:39 UTC
Permalink
Hi Sam,

I don't have time to look at build end user code today but I have had
a quick glance at the example and the first thing that jumped out as
add to me was:

osg::ref_ptr<osg::Geode> drawable(new osg::Geode);
drawable->setName("lnoflags");

geode.addChild(drawable);

Adding a Geode to a Geode is a bit odd. Why not just do
geode->setName("Inoflags");

Robert.
Sam Brkopac
2018-08-03 10:38:10 UTC
Permalink
Hi Robert,

Looks like in slimming down my code there are some things that look... odd. Different meshes can have multiple groupings of the flags so I use one geode to render all of those triangles.

Should I not be attaching the geode used to render the triangles to the main geode returned from the plugin? I guess what I'm asking is why is it odd to have a geode attached to a geode.

Thanks, Sam

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74463#74463
Robert Osfield
2018-08-03 13:53:49 UTC
Permalink
Hi Sam,

Geode used to be the leaf node in the scene graph that could only have
Drawable as children, no traditional node types could be added to a
Geode, so with older versions of the OSG what you are attempting
wouldn't even compile.

I don't recall the exact date, but in the last few years I relaxed the
scene graph so that Drawable leaves could be added to any Group in the
scene graph, so now the Geode only exists for backwards compatibility.
For a modern scene graph I wouldn't create any Geode's at all. In
doing this I had to relax the Geode so it's more in-line with a normal
Group, but this unfortunately means that you can do things like you
are doing, i.e. adding a Geode as a child to a Geode, which is an
unfortunately side effect.

In you code you are still using a Geode so it's old school OSG, but
you are nesting a Geode within a Geode, which is really not a good
practice. I really don't know why you are even using a Geode here.
It makes me think that you whole approach is a bit confused.

However, as I've only seen a tiny snippet of your code and explanation
I can't really say where you've understanding of how best to implement
what you need has gone off in the weeds. The fact that it's crashing
is a good sign that something has gone wrong, and nesting of a Geode,
even if it isn't the cause is another indication that you probably
just need to take a step back.

Another general comment is that it's not recommend practice to go
adding objects to the scene graph from within a NodeVisitor. It's all
too easy to invalidate iterators and end up in a right old mess.

Robert.
Sam Brkopac
2018-08-04 09:16:50 UTC
Permalink
Hi Robert,

Thanks for taking the time to write up your post - very informative.
Post by Robert Osfield
For a modern scene graph I wouldn't create any Geode's at all.
Most of the OSG examples use Geodes. What is the type you would use for a modern scene graph?
Post by Robert Osfield
However, as I've only seen a tiny snippet of your code and explanation
I can't really say where you've understanding of how best to implement
what you need has gone off in the weeds.
This is a very real possibility. To keep it short and sweet: I have a plugin that returns a geode from a custom file format. There is supporting data associated with the format such as walkable flags. I use Geodes to group together drawables (using the visitor) to draw them if the user wants to see them. Basically debug data for the node.
Post by Robert Osfield
Another general comment is that it's not recommend practice to go
adding objects to the scene graph from within a NodeVisitor.
Understood. Is there a best practice I can align myself with? Should I be handling that all in the plugin loader and potentially use something like osg::Switch to turn them on and off?

Thanks, Sam

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74465#74465
Robert Osfield
2018-08-05 09:02:33 UTC
Permalink
Post by Sam Brkopac
Most of the OSG examples use Geodes. What is the type you would use for a modern scene graph?
Most of the examples pre-date the change to allow Drawables to be
added directly to the scene graph. Since there are so many examples
it's a bit of task to rewrite them all. New examples won't use Geode.
Post by Sam Brkopac
Post by Robert Osfield
However, as I've only seen a tiny snippet of your code and explanation
I can't really say where you've understanding of how best to implement
what you need has gone off in the weeds.
This is a very real possibility. To keep it short and sweet: I have a plugin that returns a geode from a custom file format. There is supporting data associated with the format such as walkable flags. I use Geodes to group together drawables (using the visitor) to draw them if the user wants to see them. Basically debug data for the node.
All classes of osg::Object have support for a object->setValue("name",
valu) and bool result = object->getValue("name", value); This is what
I'd use for debug/supporting data.

Nest a Geode within a Geode is just plan bad practice. It's misusing
something that was never intended to be used in the way you were using
it. There are *no* OSG examples that do what you were doing, you've
invented a new way to misuse the OSG.
Post by Sam Brkopac
Post by Robert Osfield
Another general comment is that it's not recommend practice to go
adding objects to the scene graph from within a NodeVisitor.
Understood. Is there a best practice I can align myself with? Should I be handling that all in the plugin loader and potentially use something like osg::Switch to turn them on and off?
I don't know enough about what you are doing to pinpoint exactly what
you should use for the task. At this point you've provided a
"solution" that you want to debug, what I'm saying is the "solution"
has a number of odd things about it is likely completely the wrong way
to tackle that task.

The best way to get feedback on how to do things is provide a clear
high level explanation of what functionality you'd like to implement
then others can suggest the way they would tackle it.

Robert.

Loading...