Bug 279951 - Crash when selecting cell after creating a chart
Summary: Crash when selecting cell after creating a chart
Status: RESOLVED FIXED
Alias: None
Product: calligrasheets
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR crash
Target Milestone: ---
Assignee: Sebastian Sauer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-12 10:34 UTC by Inge Wallin
Modified: 2011-09-20 08:41 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Inge Wallin 2011-08-12 10:34:17 UTC
Application: calligratables (2.4 Alpha 3)
KDE Platform Version: 4.5.2 (KDE 4.5.2) (Compiled from sources)
Qt Version: 4.6.3
Operating System: Linux 2.6.32.26-175.fc12.i686 i686
Distribution (Platform): Fedora RPMs

-- Information about the crash:
- What I was doing when the application crashed:

1. put the following contents into A1..C3
	y	x
a	1	3
b	2	4

2. Select the area and insert a chart

3. Select "first row as label" and "first column as label"

4. (optionally) manipulate the chart

5. Select one of the cells in the area mentioned above

6. CRASH

The crash can be reproduced every time.

-- Backtrace:
Application: Tables (calligratables), signal: Aborted
[KCrash Handler]
#7  0x00f7a416 in __kernel_vsyscall ()
#8  0x00c82b91 in raise () from /lib/libc.so.6
#9  0x00c8446a in abort () from /lib/libc.so.6
#10 0x063a4ffc in qt_message_output(QtMsgType, char const*) () from /usr/lib/libQtCore.so.4
#11 0x063a51dc in ?? () from /usr/lib/libQtCore.so.4
#12 0x063a52fa in qFatal(char const*, ...) () from /usr/lib/libQtCore.so.4
#13 0x063a5386 in qt_assert(char const*, char const*, int) () from /usr/lib/libQtCore.so.4
#14 0x01a5b10a in Calligra::Tables::Cell::Cell (this=0xbfe1b0c8, sheet=0x82d99f8, col=2, row=-2) at /local/KDE/src/calligra2/tables/Cell.cpp:122
#15 0x015d5809 in Calligra::Tables::DragAndDropStrategy::DragAndDropStrategy (this=0x86b6db0, cellTool=0x8ea9460, documentPos=..., modifiers=...)
    at /local/KDE/src/calligra2/tables/ui/DragAndDropStrategy.cpp:72
#16 0x015ab537 in Calligra::Tables::CellToolBase::createStrategy (this=0x8ea9460, event=0xbfe1b3c4) at /local/KDE/src/calligra2/tables/ui/CellToolBase.cpp:1233
#17 0x00681a4a in KoInteractionTool::mousePressEvent (this=0x8ea9460, event=0xbfe1b3c4) at /local/KDE/src/calligra2/libs/flake/tools/KoInteractionTool.cpp:51
#18 0x015a96b4 in Calligra::Tables::CellToolBase::mousePressEvent (this=0x8ea9460, event=0xbfe1b3c4) at /local/KDE/src/calligra2/tables/ui/CellToolBase.cpp:889
#19 0x00620098 in KoToolProxy::mousePressEvent (this=0x8965610, event=0xbfe1bc00, point=...) at /local/KDE/src/calligra2/libs/flake/KoToolProxy.cpp:206
#20 0x0155b407 in Calligra::Tables::Canvas::mousePressEvent (this=0x8977a58, event=0xbfe1bc00) at /local/KDE/src/calligra2/tables/part/Canvas.cpp:195
#21 0x06b784c1 in QWidget::event(QEvent*) () from /usr/lib/libQtGui.so.4
#22 0x0155c23a in Calligra::Tables::Canvas::event (this=0x8977a58, e=0xbfe1bc00) at /local/KDE/src/calligra2/tables/part/Canvas.cpp:297
#23 0x06b256cc in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/libQtGui.so.4
#24 0x06b2cdae in QApplication::notify(QObject*, QEvent*) () from /usr/lib/libQtGui.so.4
#25 0x060a1f4b in KApplication::notify(QObject*, QEvent*) () from /usr/lib/libkdeui.so.5
#26 0x0649dd53 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/libQtCore.so.4
#27 0x06b2bb18 in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) () from /usr/lib/libQtGui.so.4
#28 0x06ba8eb0 in ?? () from /usr/lib/libQtGui.so.4
#29 0x06ba83c3 in QApplication::x11ProcessEvent(_XEvent*) () from /usr/lib/libQtGui.so.4
#30 0x06bd429a in ?? () from /usr/lib/libQtGui.so.4
#31 0x03b12fb8 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#32 0x03b168e8 in ?? () from /lib/libglib-2.0.so.0
#33 0x03b16a14 in g_main_context_iteration () from /lib/libglib-2.0.so.0
#34 0x064c60c6 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#35 0x06bd3e86 in ?? () from /usr/lib/libQtGui.so.4
#36 0x0649c42a in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#37 0x0649c76a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#38 0x064a0427 in QCoreApplication::exec() () from /usr/lib/libQtCore.so.4
#39 0x06b25778 in QApplication::exec() () from /usr/lib/libQtGui.so.4
#40 0x00f8738b in kdemain (argc=1, argv=0xbfe1c594) at /local/KDE/src/calligra2/tables/part/Main.cpp:43
#41 0x08048719 in main (argc=1, argv=0xbfe1c594) at /local/KDE/src/calligra2/build-master/tables/calligratables_dummy.cpp:3

Reported using DrKonqi
Comment 1 Sebastian Sauer 2011-09-01 12:38:40 UTC
Can still reproduce. Following patch shows the problem;

diff --git a/tables/ui/DragAndDropStrategy.cpp b/tables/ui/DragAndDropStrategy.cpp
index f500b5a..5f1222c 100644
--- a/tables/ui/DragAndDropStrategy.cpp
+++ b/tables/ui/DragAndDropStrategy.cpp
@@ -60,6 +60,8 @@ DragAndDropStrategy::DragAndDropStrategy(CellToolBase *cellTool,
     const KoShape *shape = tool()->canvas()->shapeManager()->selection()->firstSelectedShape();
     const QPointF position = documentPos - (shape ? shape->position() : QPointF(0.0, 0.0));
 
+    Q_ASSERT_X(position.y() >= 0., __FUNCTION__, QString("%1 ouf of bounds, documentPos=%2, shapePos=%3").arg(position.y()).arg(documentPos.y()).arg(shape ? shape->position().y() : 0.0).toLocal8Bit());
+
     // In which cell did the user click?
     qreal xpos;
     qreal ypos;

So, the logic to substract the shape's position from the absolute coordinates to reach relative coordinates is broken and produces invalid values.
Comment 2 Sebastian Sauer 2011-09-01 13:14:31 UTC
Following patch fixes it and some similar cases. But before we can apply I need to test more why this changed / doesn't provide the expected results any longer and if it's really a proper fix or breaks things at other situations.

diff --git a/tables/ui/AbstractSelectionStrategy.cpp b/tables/ui/AbstractSelectionStrategy.cpp
index f5982f9..88e5613 100644
--- a/tables/ui/AbstractSelectionStrategy.cpp
+++ b/tables/ui/AbstractSelectionStrategy.cpp
@@ -59,7 +59,7 @@ void AbstractSelectionStrategy::handleMouseMove(const QPointF& documentPos, Qt::
     Q_UNUSED(modifiers)
     Selection *const selection = d->cellTool->selection();
     const KoShape* shape = tool()->canvas()->shapeManager()->selection()->firstSelectedShape();
-    const QPointF position = documentPos - (shape ? shape->position() : QPointF(0.0, 0.0));
+    const QPointF position = documentPos /*- (shape ? shape->position() : QPointF(0.0, 0.0))*/;
     // In which cell did the user click?
     qreal xpos;
     qreal ypos;
diff --git a/tables/ui/DragAndDropStrategy.cpp b/tables/ui/DragAndDropStrategy.cpp
index f500b5a..ad1fb98 100644
--- a/tables/ui/DragAndDropStrategy.cpp
+++ b/tables/ui/DragAndDropStrategy.cpp
@@ -58,7 +58,7 @@ DragAndDropStrategy::DragAndDropStrategy(CellToolBase *cellTool,
     d->lastPoint = documentPos;
     Selection *const selection = this->selection();
     const KoShape *shape = tool()->canvas()->shapeManager()->selection()->firstSelectedShape();
-    const QPointF position = documentPos - (shape ? shape->position() : QPointF(0.0, 0.0));
+    const QPointF position = documentPos /*+ (shape ? shape->position() : QPointF(0.0, 0.0))*/;
 
     // In which cell did the user click?
     qreal xpos;
@@ -85,7 +85,7 @@ void DragAndDropStrategy::handleMouseMove(const QPointF& documentPos, Qt::Keyboa
         return;
     d->lastPoint = documentPos;
     const KoShape *shape = tool()->canvas()->shapeManager()->selection()->firstSelectedShape();
-    const QPointF position = documentPos - (shape ? shape->position() : QPointF(0.0, 0.0));
+    const QPointF position = documentPos /*- (shape ? shape->position() : QPointF(0.0, 0.0))*/;
 
     // In which cell did the user click?
     qreal xpos;
@@ -121,7 +121,7 @@ void DragAndDropStrategy::handleMouseMove(const QPointF& documentPos, Qt::Keyboa
 KUndo2Command* DragAndDropStrategy::createCommand()
 {
     const KoShape *shape = tool()->canvas()->shapeManager()->selection()->firstSelectedShape();
-    const QPointF position = d->lastPoint - (shape ? shape->position() : QPointF(0.0, 0.0));
+    const QPointF position = d->lastPoint /*- (shape ? shape->position() : QPointF(0.0, 0.0))*/;
 
     // In which cell did the user click?
     qreal xpos;
diff --git a/tables/ui/SelectionStrategy.cpp b/tables/ui/SelectionStrategy.cpp
index 8844e47..48fc486 100644
--- a/tables/ui/SelectionStrategy.cpp
+++ b/tables/ui/SelectionStrategy.cpp
@@ -45,7 +45,7 @@ SelectionStrategy::SelectionStrategy(CellToolBase *cellTool,
     d->startCell = Cell();
 
     const KoShape* shape = tool()->canvas()->shapeManager()->selection()->firstSelectedShape();
-    const QPointF position = documentPos - (shape ? shape->position() : QPointF(0.0, 0.0));
+    const QPointF position = documentPos /*- (shape ? shape->position() : QPointF(0.0, 0.0))*/;
     Sheet *const sheet = this->selection()->activeSheet();
     Selection *const selection = this->selection();
Comment 3 Sebastian Sauer 2011-09-02 08:06:46 UTC
Review-request for a patch that fixes it is up at https://git.reviewboard.kde.org/r/102517/
Comment 4 Sebastian Sauer 2011-09-20 08:41:05 UTC
Fixed with ab38a42b294765e696bb0475ed946f3d7ef7a7f2