Answered by:
Null reference exception in Microsoft.Msagl.GeometryGraph.PumpTheBoxToTheGraph when trying to recalculate layout on transformed graph

Question
-
Hi,
I am encountering a null reference pointer exception when trying to call CalculateLayout() multiple times on a GeometryGraph with a transformation applied. The following code (a modified version of CreateAndLayoutGraph() from DrawingFromGeometryGraphSample) can be used to reproduce the exception:
static internal GeometryGraph CreateAndLayoutGraph() {
double w = 30;
double h = 20;
GeometryGraph graph = new GeometryGraph();
Node a = new Node("a", new Ellipse(w, h, new P()));
Node b = new Node("b", CurveFactory.CreateBox(w, h, new P()));
graph.AddNode(a);
graph.AddNode(b);
Edge e = new Edge(a, b);
e.ArrowheadAtSource = true;
graph.AddEdge(e);
graph.AddEdge(new Edge(a,b));
graph.Transformation = PlaneTransformation.Rotation( 1.5707963267948966 );
graph.CalculateLayout();
graph.CalculateLayout();
return graph;
}
The exception occurs on the second call to CalculateLayout(), and does not occur if the Transformation line above the first CalculateLayout() is removed. Obviously there's no reason to call CalculateLayout() twice in a row like this, but my eventual goal is to be able to add/remove nodes and edges to/from the graph and re-calculate the layout. The call stack for the exception is below:
at Microsoft.Msagl.GeometryGraph.PumpTheBoxToTheGraph(Rectangle& b) in C:\dev\MSAGL_RTMJune2008\LayoutEngine\GraphLayoutApi\GeometryGraph.cs:line 598
at Microsoft.Msagl.GeometryGraph.PumpTheBoxToTheGraphWithMargins() in C:\dev\MSAGL_RTMJune2008\LayoutEngine\GraphLayoutApi\GeometryGraph.cs:line 585
at Microsoft.Msagl.Engine.RunPostLayering() in C:\dev\MSAGL_RTMJune2008\LayoutEngine\Engine\Engine.cs:line 241
at Microsoft.Msagl.Engine.Run() in C:\dev\MSAGL_RTMJune2008\LayoutEngine\Engine\Engine.cs:line 226
at Microsoft.Msagl.SugiyamaLayoutSettings.CalculateLayout(GeometryGraph msaglGraph) in C:\dev\MSAGL_RTMJune2008\LayoutEngine\GraphLayoutApi\SugiyamaLayoutSettings.cs:line 187
at Microsoft.Msagl.GeometryGraph.CalculateLayout() in C:\dev\MSAGL_RTMJune2008\LayoutEngine\GraphLayoutApi\GeometryGraph.cs:line 416
at DrawingFromMsaglGraph.Form1.CreateAndLayoutGraph() in C:\Program Files\Microsoft\Microsoft Automatic Graph Layout\Samples\DrawingFromGeometryGraphSample\Form1.cs:line 171
at DrawingFromMsaglGraph.Form1.OnPaint(PaintEventArgs e) in C:\Program Files\Microsoft\Microsoft Automatic Graph Layout\Samples\DrawingFromGeometryGraphSample\Form1.cs:line 39
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
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 DrawingFromMsaglGraph.Program.Main() in C:\Program Files\Microsoft\Microsoft Automatic Graph Layout\Samples\DrawingFromGeometryGraphSample\Program.cs:line 14
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Any ideas on why this might be happening and/or ways to get around it would be much appreciated. Thanks.
Answers
-
Please send me your email address at levnach@microsoft.com and I will send you a fixed version.
Thanks,
Lev
Lev Nachmanson- Marked as answer by DPaulB Wednesday, February 3, 2010 11:22 PM
-
You created matrix (1 0 0)
( -1 0 0),
and the intention was probably creating (1 0 0 )
( 0 -1 0)
the call graph.Transformation = new PlaneTransformation(1, 0, 0, 0, -1, 0);
will work.
Thanks
Lev Nachmanson- Marked as answer by Lev Nachmanson Saturday, December 31, 2011 5:47 PM
All replies
-
Please send me your email address at levnach@microsoft.com and I will send you a fixed version.
Thanks,
Lev
Lev Nachmanson- Marked as answer by DPaulB Wednesday, February 3, 2010 11:22 PM
-
-
-
-
-
You created matrix (1 0 0)
( -1 0 0),
and the intention was probably creating (1 0 0 )
( 0 -1 0)
the call graph.Transformation = new PlaneTransformation(1, 0, 0, 0, -1, 0);
will work.
Thanks
Lev Nachmanson- Marked as answer by Lev Nachmanson Saturday, December 31, 2011 5:47 PM