openscenegraph / OpenSceneGraph

OpenSceneGraph git repository
http://www.openscenegraph.org
Other
3.25k stars 1.42k forks source link

Program crashed during intersection detection #1214

Closed ChenKe404 closed 1 year ago

ChenKe404 commented 1 year ago

Crashed when the intersection visitor through the subclass created from osg::Node. Crashed when calling function "osgUtil::IntersectionVisitor::apply".

OSG 3.7.0(master) + osgQt(master) My subclass derived from osg::Node

ChenKe404 commented 1 year ago

_vertexArrayPtr is null 无标题

ChenKe404 commented 1 year ago

i set indices like this,i think it's right. 无标题

ChenKe404 commented 1 year ago

I create vertex array use osg::Vec3dArray before : "osg::ref_ptr vertices = new osg::Vec3dArray();" but the function "setVertexArray(unsigned int,const Vec3d)" in class "osg::TemplatePrimitiveFunctor" have nothing to do. only the function "setVertexArray(unsigned int count,const Vec3 )" could set "_vertexArraySize" and "_vertexArraySize". so I must create vertex array use class osg::Vec3Array.

I think this is a hidden bug that could cause the program to crash.

openscenegraph commented 1 year ago

I am surprised it causes a crashed, but it's correct the TemplatePrimitiveFunctor doesn't support double vertex arrays, it's a limitation rather than a bug. It shouldn't crash, instead ideally should report an unsupported error.

Graphics hardware is handles double vertex arrays very poorly so I would recommend against ever use a osg::vec3dArray as a vertex array for this reason. The only time a osg::vec3dArray is really useful in the scene graph is in cases where you have a loader that passes back double vertices with the intention of post processing the data into a form more suitable for graphics.

To handle large coordinate frames use a MatrixTransform above geometry/subgraph so that the subgraph has a local origin and can safely use float arrays suitable for graphics hardware, while the MatrixTransform places the subgraph into world coordinates. I've written about this many times on the osg-users mailing list/google group so have a look through the archives.

ChenKe404 commented 1 year ago

I got it,thanks for your help