Nullref crash when calling RenderScene
My callstack looks like this:

  at Ab3d.DirectX.RenderablePrimitive.RenderGeometry(RenderingContext renderingContext)
  at Ab3d.DirectX.RenderObjectsRenderingStep.(RenderingContext , RenderingQueue , ICamera , List`1 , Effect )
  at Ab3d.DirectX.RenderObjectsRenderingStep.(RenderingContext , Int32 , IMultiPassEffect , ReadOnlyCollection`1 , ICamera , List`1 , Effect , Boolean , Boolean )
  at Ab3d.DirectX.RenderObjectsRenderingStep.OnRun(RenderingContext renderingContext)
  at Ab3d.DirectX.RenderingStepBase.Run(RenderingContext renderingContext)
  at Ab3d.DirectX.DXScene.(RenderingContext )
  at Ab3d.DirectX.DXScene.(RenderingContext , Boolean )
  at Ab3d.DirectX.DXScene.RenderScene(Boolean forceRenderAll)
  at app.application.ui_3d.DxRenderPanel.Render() in C:\code\particulate\application\ui_3d\DxRenderPanel.cs:line 170
  at app.application.DxSceneview._updateCameraMatrices() in C:\code\particulate\application\Sceneview\DxSceneview.cs:line 161
  at app.application.DxSceneview._updateCameraMatrices(Object sender, EventArgs e) in C:\code\particulate\application\Sceneview\DxSceneview.cs:line 165
  at System.EventHandler.Invoke(Object sender, EventArgs e)
  at app.application.Cameras.CameraBase.OnTransformModified() in C:\code\particulate\application\Cameras\CameraBase.cs:line 33
  at app.application.Cameras.CameraBase.set_Transform(Matrix4 value) in C:\code\particulate\application\Cameras\CameraBase.cs:line 48
  at app.application.Cameras.CameraBase.set_Position(Vector3 value) in C:\code\particulate\application\Cameras\CameraBase.cs:line 57
  at app.application.Cameras.CameraBase.PlacePerspCameraToBoundingBag(BoundingBag3 bag, IPerspCamera camera) in C:\code\particulate\application\Cameras\CameraBase.cs:line 237
  at app.application.Cameras.DxCamera.PlaceCameraToBoundingBag(BoundingBag3 bag) in C:\code\particulate\application\Cameras\DxCamera.cs:line 125
  at app.application.DxSceneview.AutoPlaceCamera(IEnumerable`1 nodes) in C:\code\particulate\application\Sceneview\DxSceneview.cs:line 199
  at sender, EventArgs e) in C:\code\particulate\Program.cs:line 1222
  at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
  at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)
  at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
  at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
  at DevExpress.XtraEditors.XtraForm.SetVisibleCore(Boolean value)
  at DevExpress.XtraBars.Ribbon.RibbonForm.SetVisibleCore(Boolean value)
  at System.Windows.Forms.Control.set_Visible(Boolean value)
  at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
  at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
  at System.Windows.Forms.Application.Run(Form mainForm)
  at app.EntryPoint.Main() in C:\code\particulate\EntryPoint.cs:line 63

I'm quite certain this is crashing because of a MeshObjectNode, but the thing is, I don't know *why* it is crashing. The mesh object node is setup with code that looks something like this:

_sceneNode = new MeshObjectNode(
   _mesh = new GeometryMesh(),
   _material = new StandardMaterial { DiffuseColor = Colour.White.ToColor3() });

_sceneNode.Tag = this;
_mesh.Materials = _sceneNode.Materials;


var points = dataSource.Points.Value;
var indices = dataSource.Indices.Value;

_mesh.Positions = points
_mesh.Normals = PolyShapeHelpers.ComputeNormals(points, indices)
_mesh.TriangleIndices = indices;

if (_sceneNode.ParentDXScene != null)

So I'm not sure what is "null" that is causing the dxscene to crash when rendering. How can I figure out what is causing the crash? Thanks!
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

Forum Jump:

Users browsing this thread:
1 Guest(s)