         layoutFunction:Function,
         lastIndex:int = -1):Vector.<IVisualElement>
     {
-
+        if (!layer)
+            return new Vector.<IVisualElement>(0);
+        
         // TBD(hmuller): if the factory for any of the oldVisible elements isn't 
         // the specified factory (e.g. because factory is null) then 
         // removeGridElement all of them.  Maybe add removeGridElements(factory).

            
            newVisibleElements[index] = elt;
                
            layer.addGridElement(elt);
            
            elt.visible = true;
            

                        allocatedItemRenderers.push(renderer);
                }
            
                rendererLayer.addElement(renderer);
                newVisibleItemRenderers.push(renderer);
                initializeItemRenderer(renderer, rowIndex, colIndex);
                
                var colWidth:Number = gridDimensions.getColumnWidth(colIndex);
                layoutItemRenderer(renderer, cellX, cellY, colWidth, rowHeight);
                
