DXScene initialization
#1
Hi,

I have an issue with DXScene initialization. It seems that sometimes it's not correctly initialized. Is DXScene initialization an asynchronous operation? When you create a DXViewportView at the same time as WPF UserControl and try to access the DXScene property, it's null so you have to (or should as it can be initialized later) 
wait for the the event DXSceneInitialized.

If I check if the scene has IsInitialized set to true, then it is.

Thank you,
Janovský Roman

EDIT: I was digging around a bit more and the issue seems to start from DXViewportView.DXSceneInitialized which should return fully initialized scene but sometimes it returns scene that was not initialized.


Attached Files Thumbnail(s)
   
#2
The initialization and creation of the DXScene is done when the DXViewportView is loaded - to initialize the DXScene we need to know the size of the view so that the back buffers (render targets) can be created and for DirectXOverlay PresentationType the hWnd of the surface need to be created. The size is (usually) known when the control is loaded so the initialization code is executed in the DXViewportView.Loaded event handler. 

After the DXScene, DirectX device and the back buffers are created then the DXSceneInitialized event is called.

But it is possible that at load time the size of the DXViewportView is still 0. In this case the IsInitialized is set to true and the DXSceneInitialized event is called but the back buffers are not created. In this case the IsEnabled property is set to false - it is set to true when the valid size is set.


From the screenshot I see that you are defining multiple DXViewportViews in a Grid. Note that when the row width and height are defined with a star then the size  is evenly distributed between cells. But in case you are using GridSplitter and if used have manually change the size of the Grid with GridSplitter and if you then add another column / row with size set to star, then the size of the newly created cells will be 0 - so the DXViewportView will be created and loaded into a 0x0 space. In this case you need to manually resize the grid to show the control.

But maybe there is some other reason for the problem - I see that you are using a pre-release version of DXEngine with using multiple DXViewportViews that show the same DXScene. In this case it would be great if you could update the sample that I have sent to you so that I would be able to reproduce the problem.
Andrej Benedik
#3
What you described seems to correspond with the errors I got from DebugView++ and system messages. The texture size was 1x1 and required size was ~600x250. I managed to hopefully resolve this by moving the creation of DXViewportView into UserControl.Loaded event.

What is weird is, that DXScene.IsInitialized was set to false yet the DXSceneInitialized was called nevertheless.

I am using multiple DXViewportViews and each has its own DXScene for now (the older approach, not the one in preview). I will make sure to update the views once the grid splitters will be added. Wouldn't the sizing issue be resolved if ActualHeight and ActualWidth properties from FrameworkElement were used for DXViewportView? These properties should be always available and can be accessed from SizeChanged event.

Do you have some lifecycle diagram/description of DXEngine entities and when they are executed? Like that the creation of DXViewportView is handled in Loaded event. Also SceneNodes have Update() method that should be called from CompositionTarget.Rendering and DXScene.Update(). If I wanted to execute some code before any SceneNode is updated is there an event for this (like there is the AfterUpdated event on DXScene)?
#4
The code that gets the size already reads the ActualWidth and ActualHeight. If they are not defined then Width and Height are read.

DXSceneInitialized event is called from DXViewportView - in case WPF 3D rendering is used, then the DXScene is not be initialized. You can check that with DXViewportView.UsedGraphicsProfile. WPF 3D can be used as a fallback if there was an error during initialization.

Is it possible that you create a simple project and send it to my email so that I can reproduce your issues and can check that in more details. It is quiet hard to guess what could be the cause if I do not have enough information.


An event that is triggered before Update is DXViewportView.SceneUpdating.

If you want to get more details on how DXEngine works, you can read the "Deep dive article" here: https://www.ab4d.com/DirectX/3D/DXEngineDeepDive.aspx
Andrej Benedik
  


Forum Jump:


Users browsing this thread:
1 Guest(s)