Hello,
I have a tree diagram that was having performance issues and I am trying to convert it over to a virtual tree. I am using the Virtualization sample as a guide. I have built the sample code and it works just fine for me. However, I am having a problem with my application. For starters, the FindRoots() method in the VirtualizingTreeLayout class is called more than once and it’s causing a problem.
Here is the code from the sample for FindRoots():
// need to find root Node(s); which in this case means creating the actual Nodes,
// since they would otherwise not exist
protected override void FindRoots()
{
foreach (VirtualizingTreeVertex v in this.Network.Vertexes)
{
if ((this.Path == TreePath.Destination && v.SourceEdgesCount == 0) ||
(this.Path == TreePath.Source && v.DestinationEdgesCount == 0))
{
var node = this.Diagram.PartManager.AddNodeForData(v.Data, _Model);
if (node == null) throw new Exception("Root node data doesn’t have Location at (0,0): " + v.Data.ToString());
((VirtualizingTreeNetwork)this.Network).SetNode(v, node);
this.Roots.Add(node);
}
}
if (this.Roots.Count == 0) throw new Exception(“Found no root node for tree”);
}
The first time FindRoots() is called the node variable is returned from AddNodeForData(), but in the subsequent time it is null and the exception is thrown.
My call stack looks like this for the 2nd call to FindRoots():
<span =“Apple-tab-span” style="white-space: pre; "> WindchillQualitySolutions.Web.Silverlight!MyApp.Web.MyTree.VirtualizingTreeLayout.FindRoots() Line 129<span =“Apple-tab-span” style="white-space: pre; "> C#
<span =“Apple-tab-span” style=“white-space:pre”> Northwoods.GoSilverlight!Northwoods.GoXam.Layout.TreeLayout.CreateTrees() + 0x413 bytes<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> Northwoods.GoSilverlight!Northwoods.GoXam.Layout.TreeLayout.DoLayout(System.Collections.Generic.IEnumerable<Northwoods.GoXam.Node> nodes = {System.Linq.Enumerable.WhereEnumerableIterator<Northwoods.GoXam.Node>}, System.Collections.Generic.IEnumerable<Northwoods.GoXam.Link> links = {System.Linq.Enumerable.WhereEnumerableIterator<Northwoods.GoXam.Link>}) + 0x46a bytes<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> WindchillQualitySolutions.Web.Silverlight!MyApp.Web.MyTree.FTDiagramTreeLayout.DoLayout(System.Collections.Generic.IEnumerable<Northwoods.GoXam.Node> nodes = {System.Linq.Enumerable.WhereEnumerableIterator<Northwoods.GoXam.Node>}, System.Collections.Generic.IEnumerable<Northwoods.GoXam.Link> links = {System.Linq.Enumerable.WhereEnumerableIterator<Northwoods.GoXam.Link>}) Line 37 + 0x13 bytes<span =“Apple-tab-span” style=“white-space:pre”> C#
<span =“Apple-tab-span” style=“white-space:pre”> Northwoods.GoSilverlight!Northwoods.GoXam.Layout.MultiLayout.DoLayout(System.Collections.Generic.IEnumerable<Northwoods.GoXam.Node> nodes = {System.Linq.Enumerable.WhereEnumerableIterator<Northwoods.GoXam.Node>}, System.Collections.Generic.IEnumerable<Northwoods.GoXam.Link> links = {System.Linq.Enumerable.WhereEnumerableIterator<Northwoods.GoXam.Link>}) + 0x593 bytes<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> Northwoods.GoSilverlight!Northwoods.GoXam.LayoutManager.PerformLayout() + 0x496 bytes<span =“Apple-tab-span” style=“white-space:pre”>
><span =“Apple-tab-span” style=“white-space:pre”> Northwoods.GoSilverlight!Northwoods.GoXam.LayoutManager.#Xf() + 0x220 bytes<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> [Native to Managed Transition]<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> [Managed to Native Transition]<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> mscorlib.dll!System.Delegate.DynamicInvokeImpl(object[] args) + 0x6b bytes<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> System.Windows.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0x26 bytes<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> System.Windows.dll!System.Windows.Threading.Dispatcher.Dispatch(System.Windows.Threading.DispatcherPriority priority) + 0xd5 bytes<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> System.Windows.dll!System.Windows.Threading.Dispatcher.OnInvoke(object context) + 0xa bytes<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> System.Windows.dll!System.Windows.Hosting.CallbackCookie.Invoke(object[] args) + 0x16 bytes<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> System.Windows.RuntimeHost.dll!System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(System.IntPtr pHandle, int nParamCount, System.Windows.Hosting.NativeMethods.ScriptParam[] pParams, ref System.Windows.Hosting.NativeMethods.ScriptParam pResult = {System.Windows.Hosting.NativeMethods.ScriptParam}) + 0xe9 bytes<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> [Appdomain Transition]<span =“Apple-tab-span” style=“white-space:pre”>
A few notes:
-
If I have a small tree (3 or 4 nodes) then this problem doesn’t happen. It only happens when I have a large tree where some of the nodes are offscreen.
-
If I save the node in the 1st call and return it in the 2nd call then later on I get errors when TreeLayout::LayoutTree() is called with a null TreeVertex.
So my questions are:
-
What is causing this? I have a single root of my tree and it isn’t changing. Why does the Roots get cleared and need to be regenerated anyway?
-
How can I tell what is triggering the layout?
-
This might be a symptom of a larger problem. It’s very likely I have set up something else wrong. I can post any other code that you think might be useful.
Thanks,
-Robert