helix-toolkit / helix-toolkit

Helix Toolkit is a collection of 3D components for .NET.
http://helix-toolkit.org/
MIT License
1.85k stars 661 forks source link

Viewport3DX hangs when BelongsToParentWindow=False with EffectsManager #2265

Open ericmschmidt opened 2 weeks ago

ericmschmidt commented 2 weeks ago

We are using the HelixToolkit.SharpDx package in one of our projects and we recently defined our Viewport3DX with the BelongsToParentWindow=False to allow for docking behaviors, as described in Issue 1288. Upon release, our users noticed that the application no longer closes successfully. I traced the behavior back to when we defined this feature. Upon further investigation, I found that if I removed initializing an EffectsBehavior (a DefaultEffectsBehavior in our case) the application will close out as expected. However, removing this means none of the visuals display.

In looking at the BelongsToParentWindow implementation, it looks like the EffectsManager gets set to null but I found that it needed to be disposed before setting it to null. In addition, I don't see how the Viewport3DX is ever disposed of when it doesn't belong to a parent window. In that instance do we have to manually call Viewport.Dispose()?

I've attached a small sample project (though I also tested this in the CoreWpfTest example project and saw the same issue. HelixSharpDx.NET.zip

holance commented 2 weeks ago

You can dispose EffectsManager with window close event which needs to be controlled by your own code

ericmschmidt commented 1 week ago

I tested out disposing of the EffectsManager during the closing event and that does seem to fix the issue of our application hanging.

Should this be defined in the Viewport's Dispose method? Also, if we set BelongsToParentWindow=False, does our application need to call Viewport3DX.Dispose() as well, or does the Viewport get handled differently? If the Viewport's Dispose method does get called then is there a reason that the Viewport doesn't dispose the EffectsManager instead of setting it to null?

holance commented 1 week ago

You can try to call Viewport.dispose as well if you have multiple viewports sharing same EffectsManager.