         totalSize += @getMainCoordinate page.getCurrentSize()
         break if totalSize >= pixelsOnScreen
 
-      if totalSize < pixelsOnScreen
+      if totalSize < pixelsOnScreen && pages.length > 0 && totalSize > 0
         averagePageSize = totalSize / pages.length
         pixelsLeft = pixelsOnScreen - totalSize
         count += ceil pixelsLeft / averagePageSize

        totalSize += @getMainCoordinate page.getCurrentSize()
        break if totalSize >= pixelsOnScreen

      if totalSize < pixelsOnScreen
        averagePageSize = totalSize / pages.length
        pixelsLeft = pixelsOnScreen - totalSize
        count += ceil pixelsLeft / averagePageSize

        #     atEndEdge: atEndEdge

        if referenceFrame.page && 0 > pages.indexOf referenceFrame.page
          console.warn(
            """
            PagingScrollElement#pages setter: New page list does not contain the current referenceFrame. ALWAYS include the current referenceFrame when setting pages. Screen will jump!

            page keys: #{inspect (page.key for page in pages)}
            """
          )

        if referenceFrame.page != page || referenceFrame.atEndEdge != atEndEdge
          # setReferenceFrame will call _updatePagesSplit
