Cross thread Geometry building

Nov 7, 2010 at 2:29 PM

I’m trying build a mesh on another thread. I’ve created my own object which inherits from Geometry. When I try to instantiate the object on another thread I get a cross thread error: Invalid cross-thread access.

Why is this? I’m not trying to add the mesh to the scene yet, and I’m not accessing any other controls to create the object (at least on my side) Is creating instances of Geometry objects on threads other than the UI thread not supported?

My current plan is to build all the necessary components (faces, verts, text cooards) and then pass them back, and have the actual mesh build on the main UI thread. Mostly I’m just curious why I can’t create a mesh on another thread. It’s just data right?

My order of operations.
1) Get Game up and running with initial nodes.
2) At some point I detect I need to create a mesh(geometry). I create a thread, pass in the necessary data and create the geometry object.
3) I detect the geometry is finished building on the UI thread, at this point the thread I used to create the geometry is finished.
4) I take the geometry created and add it to the scene. This operation happens on the UI thread.

I can't get past step 2 because creating the instance of the geometry on another thread fails.

Coordinator
Nov 7, 2010 at 3:46 PM

What object is it that you're trying to instantiate - most objects are DependencyObjects in Balder, so creating them on a non-UI thread wouldn't be permitted by Silverlight.

What you could do though. The GeometryContext within a Geometry is not a DependencyObject - you could work with that one on another thread. 

Nov 7, 2010 at 5:10 PM
Edited Nov 7, 2010 at 5:11 PM


I was using the Geometry object directly as a base for my own custom class.  I'm glad I posted even though I found a workaround.  I think your solution of using the context is better than mine.  I'll give that a go.

 Thanks again for the hard work, and for posting responses to these discussions. 

Coordinator
Nov 7, 2010 at 5:39 PM

No problem. Glad I can help.

Nov 11, 2010 at 12:13 AM

while working through how to use the GemetryContext in the way you suggested I noticed DetailLevel.  I see there is a Full and Low right now.  Is that meant to do what I'm trying to do?  Provide a high vs low polycount model?  Does Balder switch between these two depending on some factor?

 

	public enum DetailLevel
	{
		Full=1,
		Low,
		Wireframe,
		BoundingBox
	}

 


Coordinator
Nov 11, 2010 at 5:30 AM

Its in there for future expansion. Balder will be doing this in the future. The only thing its using this for today is when you have PassiveRendering enabled and you set the PassiveRenderingMode to BoundingBox - when interaction is done it will render with BoundingBox and switch to Full when interaction is done. So for now, the only thing that'll work is the Full one - and you have a convenience property for that one; FullDetailLevel on the Geometry.