Bug 819248 - avoid adding null Layers into the output of SortLayersBy3DZOrder - r=mattwoodrow
authorBenoit Jacob <bjacob@mozilla.com>
Mon, 17 Dec 2012 16:12:55 -0500
changeset 125515 985bab8f84dfe203e9735a1937d2fbfa32f4d3e4
parent 125514 3ecf6d05c4e280cf1631e415e58e86c24d1cff23
child 125516 f3d710952f62d5ab8d11c330364967756d81111e
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs819248
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 819248 - avoid adding null Layers into the output of SortLayersBy3DZOrder - r=mattwoodrow
gfx/layers/LayerSorter.cpp
--- a/gfx/layers/LayerSorter.cpp
+++ b/gfx/layers/LayerSorter.cpp
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "LayerSorter.h"
 #include "DirectedGraph.h"
 #include "limits.h"
 #include "gfxLineSegment.h"
 #include "Layers.h"
+#include "mozilla/Assertions.h"
 
 namespace mozilla {
 namespace layers {
 
 enum LayerSortOrder {
   Undefined,
   ABeforeB,
   BBeforeA,
@@ -273,16 +274,17 @@ void SortLayersBy3DZOrder(nsTArray<Layer
 
   // Move each item without incoming edges into the sorted list,
   // and remove edges from it.
   do {
     if (!noIncoming.IsEmpty()) {
       uint32_t last = noIncoming.Length() - 1;
 
       Layer* layer = noIncoming.ElementAt(last);
+      MOZ_ASSERT(layer); // don't let null layer pointers sneak into sortedList
 
       noIncoming.RemoveElementAt(last);
       sortedList.AppendElement(layer);
 
       nsTArray<DirectedGraph<Layer*>::Edge> outgoing;
       graph.GetEdgesFrom(layer, outgoing);
       for (uint32_t i = 0; i < outgoing.Length(); i++) {
         DirectedGraph<Layer*>::Edge edge = outgoing.ElementAt(i);
@@ -306,19 +308,21 @@ void SortLayersBy3DZOrder(nsTArray<Layer
           minEdges = edgeCount;
           minNode = aLayers.ElementAt(i);
           if (minEdges == 1) {
             break;
           }
         }
       }
 
-      // Remove all of them!
-      graph.RemoveEdgesTo(minNode);
-      noIncoming.AppendElement(minNode);
+      if (minNode) {
+        // Remove all of them!
+        graph.RemoveEdgesTo(minNode);
+        noIncoming.AppendElement(minNode);
+      }
     }
   } while (!noIncoming.IsEmpty());
   NS_ASSERTION(!graph.GetEdgeCount(), "Cycles detected!");
 #ifdef DEBUG
   if (gDumpLayerSortList) {
     fprintf(stderr, " --- Layers after sorting: --- \n");
     DumpLayerList(sortedList);
   }