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 

Crash when using LineSegmentIntersector


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
sbrkopac
Newbie


Joined: 14 Jun 2018
Posts: 12

PostPosted: Thu Aug 02, 2018 10:03 pm    Post subject:
Crash when using LineSegmentIntersector
Reply with quote

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

Operating System: Windows 10
Compiler: Visual Studio 2017 (V 15.7.2)
OSG Version: 3.6.1

Thanks, Sam
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12149

PostPosted: Fri Aug 03, 2018 8:39 am    Post subject:
Crash when using LineSegmentIntersector
Reply with quote

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.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
sbrkopac
Newbie


Joined: 14 Jun 2018
Posts: 12

PostPosted: Fri Aug 03, 2018 10:38 am    Post subject:
Reply with quote

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.

edit: For clarity sake I added a comment with the actual function visitor from the code base.

Thanks, Sam
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12149

PostPosted: Fri Aug 03, 2018 1:55 pm    Post subject:
Crash when using LineSegmentIntersector
Reply with quote

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.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
sbrkopac
Newbie


Joined: 14 Jun 2018
Posts: 12

PostPosted: Sat Aug 04, 2018 9:16 am    Post subject:
Reply with quote

Hi Robert,

Thanks for taking the time to write up your post - very informative.

Quote:
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?

Quote:
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.

Quote:
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
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12149

PostPosted: Sun Aug 05, 2018 9:03 am    Post subject:
Crash when using LineSegmentIntersector
Reply with quote

On Sat, 4 Aug 2018 at 17:24, Sam Brkopac <> wrote:
Quote:
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.

Quote:


Quote:
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.

Quote:
Quote:
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.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
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 osgUtil::LineSegmentIntersector perfo... Andrea74 General 6 Tue Dec 04, 2018 4:09 pm View latest post
No new posts osgText 3.6.3 crash Trajce Nikolov NICK General 2 Wed Sep 12, 2018 12:25 pm View latest post
No new posts [Crash issue] no error info even set ... pwang General 1 Sun Jul 29, 2018 1:20 pm View latest post
No new posts [Crash issue] How to add&remove d... pwang General 2 Thu Jul 26, 2018 10:10 am View latest post
No new posts RayIntersector with KdTree causes a c... Ale General 15 Thu Jul 26, 2018 9:33 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