diff --git a/AsyncDisplayKit/Details/ASFlowLayoutController.mm b/AsyncDisplayKit/Details/ASFlowLayoutController.mm index 115b38a0e1..26bed9eb83 100644 --- a/AsyncDisplayKit/Details/ASFlowLayoutController.mm +++ b/AsyncDisplayKit/Details/ASFlowLayoutController.mm @@ -153,7 +153,7 @@ static const std::pair ASFindIndexForRange(const std::vector cur = pos, pre = pos; - if (range < 0.0 && cur.first >= 0 && cur.second >= 0) { + if (range < 0.0 && cur.first >= 0 && cur.first < nodes.size() && cur.second >= 0 && cur.second < nodes[cur.first].size()) { // search backward while (range < 0.0 && cur.first >= 0 && cur.second >= 0) { pre = cur; @@ -170,7 +170,7 @@ static const std::pair ASFindIndexForRange(const std::vector 0.0 && cur.first < nodes.size() && cur.second < nodes[cur.first].size()) { + while (range > 0.0 && cur.first >= 0 && cur.first < nodes.size() && cur.second >= 0 && cur.second < nodes[cur.first].size()) { pre = cur; CGSize size = nodes[cur.first][cur.second]; range -= layoutDirection == ASFlowLayoutDirectionHorizontal ? size.width : size.height;