Nullref crash when calling RenderScene
I cannot reproduce your problem. To reproduce it, I added the following code to CreateObjectsScene method in the PictureBoxForm.cs file in the Ab3d.DXEngine.WinForms.Sample project:

           var mesh = new GeometryMesh();
           var material = new StandardMaterial {DiffuseColor = Colors.White.ToColor3()};

           var _sceneNode = new MeshObjectNode(mesh, material);

           _sceneNode.Tag  = this;
           mesh.Materials = _sceneNode.Materials;


           var sphereMesh3D = new Ab3d.Meshes.SphereMesh3D(new Point3D(), 10, 10);

           List<Point3D> points  = sphereMesh3D.Geometry.Positions.ToList();
           var           indices = sphereMesh3D.Geometry.TriangleIndices;

           mesh.Positions = points.Select(p => Ab3d.DirectX.Extentions.ToVector3(p)).ToArray();

           mesh.Normals = sphereMesh3D.Geometry.Normals.Select(p => Ab3d.DirectX.Extentions.ToVector3(p)).ToArray();

           mesh.TriangleIndices = indices;

           if (_sceneNode.ParentDXScene != null)

This works fine.

Anyway, from the source from RenderGeometry method I assume that your code was executed before the DirectX device was created. This way the DirectX resources (VertexBufferBinding array) in GeometryMesh was not created when you called RecreateMesh method.

If DirectX device is created later, you need to call InitializeResources on the SceneNode to created DirectX resources.

InitializeResources is also called when you add SceneNode to parent's SceneNode ("_dxScene.RootNode.AddChild(_sceneNode);"), but it parent not was not yet initialized, then the added node also cannot be initialized. Therefore it is recommended to add the MeshObjectNode to parent SceneNode after all the properties are set.

Final note:
It is possible to use DXEngine without DXViewportView and with using only DXScene and SceneNodes, but this is hard because this not very well documented and there are not a lot of samples. Even when you are using WinForms it is recommended to use DXViewportView - see the DXViewportViewDemo.cs in the WinForms sample project for a code template. This still allows you to use SharpDX's RenderForm and also provides you with easy to use WPF objects.
Andrej Benedik

Messages In This Thread
RE: Nullref crash when calling RenderScene - by abenedik - 03-07-2018, 11:49 AM

Forum Jump:

Users browsing this thread:
1 Guest(s)