fixing a crash if there are no visible messages in a chatscene
authorMarcus Eggenberger <egs@quassel-irc.org>
Mon, 27 Oct 2008 12:58:16 +0000 (13:58 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Mon, 27 Oct 2008 12:58:16 +0000 (13:58 +0100)
src/qtui/chatscene.cpp

index f71c857..c24933a 100644 (file)
@@ -573,9 +573,14 @@ void ChatScene::updateSceneRect(qreal width) {
   }
 
   // the following call should be safe. If it crashes something went wrong during insert/remove
-  ChatLine *firstLine = _lines.at(_firstLineRow);
-  ChatLine *lastLine = _lines.last();
-  updateSceneRect(QRectF(0, firstLine->pos().y(), width, lastLine->pos().y() + lastLine->height() - firstLine->pos().y()));
+  if(_firstLineRow < _lines.count()) {
+    ChatLine *firstLine = _lines.at(_firstLineRow);
+    ChatLine *lastLine = _lines.last();
+    updateSceneRect(QRectF(0, firstLine->pos().y(), width, lastLine->pos().y() + lastLine->height() - firstLine->pos().y()));
+  } else {
+    // empty scene rect
+    updateSceneRect(QRectF(0, 0, width, 0));
+  }
 }
 
 void ChatScene::updateSceneRect(const QRectF &rect) {