Hi Kate devs! I coded a tiny (but very useful) KTextEditor plugin called AutoBrace, and it works great - thanks for the nice plugin interface! - apart from a reliably reproducible crash in KateView::setCursorPosition(). The plugin inserts a new line with a closing brace after a line like blah { so that the line following that one stays empty (like without the plugin) but the line after that contains the newly inserted brace, like this: } Because of the insertion, I need to The relevant code in AutoBracePlugin::slotTextInserted() (which is connected to the KTextEditor::Document::textInserted() signal) goes as follows: (...) // Insert the empty line + brace, and adjust the cursor position. if (insertBrace) { document->insertText(range.end(), "\n" + indentation + "}"); } document->activeView()->setCursorPosition( document->endOfLine(range.end().line()) ); } That works nicely when the "blah {" line is not the last line in the document, but when it is the last line, Kate dumps with the following crash on the setCursorPosition() call. I'm not all too familiar with the KatePart internals - is there anything that this code does wrong, or anything that I can do to avoid the crash? Otherwise, a fix from you guys would be terribly nice. Application: Kate (kate), signal SIGABRT Thread 1 (Thread 0xb5b12930 (LWP 28079)): [KCrash Handler] #6 0xb7ffa430 in __kernel_vsyscall () #7 0xb6793880 in raise () from /lib/tls/i686/cmov/libc.so.6 #8 0xb6795248 in abort () from /lib/tls/i686/cmov/libc.so.6 #9 0xb6aae795 in qt_message_output () from /usr/lib/libQtCore.so.4 #10 0xb6aae872 in qFatal () from /usr/lib/libQtCore.so.4 #11 0xb6aae915 in qt_assert () from /usr/lib/libQtCore.so.4 #12 0xb435a104 in KateViewInternal::endPos (this=0x8608698) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:329 #13 0xb435fda2 in KateViewInternal::makeVisible (this=0x8608698, c=@0x860873c, endCol=0, force=false, center=true, calledExternally=true) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:630 #14 0xb436046b in KateViewInternal::updateCursor (this=0x8608698, newCursor=@0xbfff87a0, force=false, center=true, calledExternally=true) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:1875 #15 0xb434bdd5 in KateView::setCursorPositionInternal (this=0x8629d40, position=@0xbfff8828, tabwidth=1, calledExternally=true) at /home/kde4/kde/src/kdelibs/kate/view/kateview.cpp:1092 #16 0xb434be88 in KateView::setCursorPosition (this=0x8629d40, position={_vptr.Cursor = 0xbfff8828, m_line = 1, m_column = 0, m_range = 0x86d7bd0}) at /home/kde4/kde/src/kdelibs/kate/view/kateview.cpp:2292 #17 0xb592c374 in AutoBracePlugin::slotTextInserted (this=0x83a5d38, document=0x84eb548, range=@0xbfff89e8) at /home/kde4/kde/src/playground-devtools/kte_autobrace/autobrace.cpp:110 #18 0xb592c45b in AutoBracePlugin::qt_metacall (this=0x83a5d38, _c=QMetaObject::InvokeMetaMethod, _id=1, _a=0xbfff8978) at /home/kde4/kde/build/autobrace/autobrace.moc:72 #19 0xb6bbba60 in QMetaObject::activate () from /usr/lib/libQtCore.so.4 #20 0xb6bbc7e2 in QMetaObject::activate () from /usr/lib/libQtCore.so.4 #21 0xb631f3c9 in KTextEditor::Document::textInserted (this=0x84eb548, _t1=0x84eb548, _t2=@0xbfff89e8) at /home/kde4/kde/build/kdelibs/interfaces/ktexteditor/document.moc:161 #22 0xb42d7fdd in KateDocument::editWrapLine (this=0x84eb548, line=0, col=7, newLine=true, newLineAdded=0x0) at /home/kde4/kde/src/kdelibs/kate/document/katedocument.cpp:1394 #23 0xb42d93e9 in KateDocument::newLine (this=0x84eb548, v=0x8629d40) at /home/kde4/kde/src/kdelibs/kate/document/katedocument.cpp:4076 #24 0xb435e83f in KateViewInternal::doReturn (this=0x8608698) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:768 #25 0xb435eb25 in KateViewInternal::keyPressEvent (this=0x8608698, e=0xbfff8fbc) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:2295 #26 0xb435e336 in KateViewInternal::eventFilter (this=0x8608698, obj=0x8608698, e=0xbfff8fbc) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:2206 #27 0xb6ba604a in QCoreApplicationPrivate::sendThroughObjectEventFilters () from /usr/lib/libQtCore.so.4 #28 0xb70458ca in QApplicationPrivate::notify_helper () from /usr/lib/libQtGui.so.4 #29 0xb704e846 in QApplication::notify () from /usr/lib/libQtGui.so.4 #30 0xb7b62bb3 in KApplication::notify (this=0xbfff9a2c, receiver=0x8608698, event=0xbfff8fbc) at /home/kde4/kde/src/kdelibs/kdeui/kernel/kapplication.cpp:307 #31 0xb6ba6e61 in QCoreApplication::notifyInternal () from /usr/lib/libQtCore.so.4 #32 0xb70a641e in ?? () from /usr/lib/libQtGui.so.4 #33 0xb70dcbf0 in ?? () from /usr/lib/libQtGui.so.4 #34 0xb70ded66 in ?? () from /usr/lib/libQtGui.so.4 #35 0xb70b5b35 in QApplication::x11ProcessEvent () from /usr/lib/libQtGui.so.4 #36 0xb70e07ea in ?? () from /usr/lib/libQtGui.so.4 #37 0xb5f0a6f8 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0 #38 0xb5f0dda3 in ?? () from /usr/lib/libglib-2.0.so.0 #39 0xb5f0df61 in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0 #40 0xb6bd1478 in QEventDispatcherGlib::processEvents () from /usr/lib/libQtCore.so.4 #41 0xb70dfee5 in ?? () from /usr/lib/libQtGui.so.4 #42 0xb6ba552a in QEventLoop::processEvents () from /usr/lib/libQtCore.so.4 #43 0xb6ba56ea in QEventLoop::exec () from /usr/lib/libQtCore.so.4 #44 0xb6ba7da5 in QCoreApplication::exec () from /usr/lib/libQtCore.so.4 #45 0xb7045767 in QApplication::exec () from /usr/lib/libQtGui.so.4 #46 0xb7fda2bb in kdemain (argc=1, argv=0xbfff9fa4) at /home/kde4/kde/src/kdesdk/kate/app/katemain.cpp:250 #47 0x080486b6 in main (argc=) at /home/kde4/kde/build/kdesdk/kate/app/kate_dummy.cpp:3 P.S.: The list of selectable versions in Bugzilla is *slightly* out of date. I hope you don't mind if I selected "CVS", as "SVN" is not available :P
> Because of the insertion, I need to <end-of-paragraph> Er, oops. That should go something like > Because of the insertion, I need to set back the cursor to the empty line, > otherwise it gets shifted to after the closing brace, which is bad usability.
If I replace the above setCursorPosition() call with something more straightforward, otherwise the same piece of code as above: (...) // Insert the empty line + brace, and adjust the cursor position. if (insertBrace) { document->insertText(range.end(), "\n" + indentation + "}"); } document->activeView()->setCursorPosition(range.end()); } (after all, it's not like I could hope to insert indentation by myself, so the endOfLine() stuff in setCursorPosition() is not required anyways) then the backtrace is different and goes like this: (It might not be as useless as KCrash says it is.) ---- This backtrace appears to be of no use. This is probably because your packages are built in a way which prevents creation of proper backtraces, or the stack frame was seriously corrupted in the crash. [Thread debugging using libthread_db enabled] [New Thread 0xb5c07930 (LWP 323)] 0xb80ef430 in __kernel_vsyscall () [Current thread is 0 (process 323)] Thread 1 (Thread 0xb5c07930 (LWP 323)): #0 0xb80ef430 in __kernel_vsyscall () #1 0xb68f9dc0 in __nanosleep_nocancel () from /lib/tls/i686/cmov/libc.so.6 #2 0xb68f9bfe in sleep () from /lib/tls/i686/cmov/libc.so.6 #3 0xb7cc65b2 in KCrash::startDrKonqi (argv=0xbffef1f0, argc=17) at /home/kde4/kde/src/kdelibs/kdeui/util/kcrash.cpp:412 #4 0xb7cc7104 in KCrash::defaultCrashHandler (sig=11) at /home/kde4/kde/src/kdelibs/kdeui/util/kcrash.cpp:337 #5 <signal handler called> #6 0xb68d5b56 in memcpy () from /lib/tls/i686/cmov/libc.so.6 #7 0x8b14c008 in ?? () #8 0xb734ec17 in ?? () from /usr/lib/libQtGui.so.4 #9 0xb734a5f0 in QTextLine::cursorToX () from /usr/lib/libQtGui.so.4 #10 0xb4419665 in QTextLine::cursorToX (this=0xbffefd3c, cursorPos=0, edge=QTextLine::Leading) at /usr/include/qt4/QtGui/qtextlayout.h:210 #11 0xb446bf08 in KateViewInternal::cursorToCoordinate (this=0x93ca3b8, cursor=@0xbffefdc4, realCursor=true, includeBorder=false) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:732 #12 0xb446c03c in KateViewInternal::inputMethodQuery (this=0x93ca3b8, query=Qt::ImMicroFocus) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:3603 #13 0xb76ae701 in ?? () from /usr/lib/libQtGui.so.4 #14 0xb41ffb02 in ?? () from /usr/lib/qt4/plugins/inputmethods/libqimsw-multi.so #15 0xb7187300 in QWidget::updateMicroFocus () from /usr/lib/libQtGui.so.4 #16 0xb446f4aa in KateViewInternal::updateCursor (this=0x93ca3b8, newCursor=@0xbffeff90, force=false, center=true, calledExternally=true) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:1883 #17 0xb445add5 in KateView::setCursorPositionInternal (this=0x92b1d58, position=@0xbfff0018, tabwidth=1, calledExternally=true) at /home/kde4/kde/src/kdelibs/kate/view/kateview.cpp:1092 #18 0xb445ae88 in KateView::setCursorPosition (this=0x92b1d58, position={_vptr.Cursor = 0xbfff0018, m_line = -1073807320, m_column = 0, m_range = 0xbfff0040}) at /home/kde4/kde/src/kdelibs/kate/view/kateview.cpp:2292 #19 0xb5a3b35c in AutoBracePlugin::slotTextInserted (this=0x912bcf8, document=0x9258d38, range=@0xbfff01d8) at /home/kde4/kde/src/playground-devtools/kte_autobrace/autobrace.cpp:110 #20 0xb5a3b443 in AutoBracePlugin::qt_metacall (this=0x912bcf8, _c=QMetaObject::InvokeMetaMethod, _id=1, _a=0xbfff0168) at /home/kde4/kde/build/autobrace/autobrace.moc:72 #21 0xb6cb0a60 in QMetaObject::activate () from /usr/lib/libQtCore.so.4 #22 0xb6cb17e2 in QMetaObject::activate () from /usr/lib/libQtCore.so.4 #23 0xb64143c9 in KTextEditor::Document::textInserted (this=0x9258d38, _t1=0x9258d38, _t2=@0xbfff01d8) at /home/kde4/kde/build/kdelibs/interfaces/ktexteditor/document.moc:161 #24 0xb43e6fdd in KateDocument::editWrapLine (this=0x9258d38, line=2, col=7, newLine=true, newLineAdded=0x0) at /home/kde4/kde/src/kdelibs/kate/document/katedocument.cpp:1394 #25 0xb43e83e9 in KateDocument::newLine (this=0x9258d38, v=0x92b1d58) at /home/kde4/kde/src/kdelibs/kate/document/katedocument.cpp:4076 #26 0xb446d83f in KateViewInternal::doReturn (this=0x93ca3b8) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:768 #27 0xb446db25 in KateViewInternal::keyPressEvent (this=0x93ca3b8, e=0xbfff07ac) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:2295 #28 0xb446d336 in KateViewInternal::eventFilter (this=0x93ca3b8, obj=0x93ca3b8, e=0xbfff07ac) at /home/kde4/kde/src/kdelibs/kate/view/kateviewinternal.cpp:2206 #29 0xb6c9b04a in QCoreApplicationPrivate::sendThroughObjectEventFilters () from /usr/lib/libQtCore.so.4 #30 0xb713a8ca in QApplicationPrivate::notify_helper () from /usr/lib/libQtGui.so.4 #31 0xb7143846 in QApplication::notify () from /usr/lib/libQtGui.so.4 #32 0xb7c57bb3 in KApplication::notify (this=0xbfff121c, receiver=0x93ca3b8, event=0xbfff07ac) at /home/kde4/kde/src/kdelibs/kdeui/kernel/kapplication.cpp:307 #33 0xb6c9be61 in QCoreApplication::notifyInternal () from /usr/lib/libQtCore.so.4 #34 0xb719b41e in ?? () from /usr/lib/libQtGui.so.4 #35 0xb71d1bf0 in ?? () from /usr/lib/libQtGui.so.4 #36 0xb71d3d66 in ?? () from /usr/lib/libQtGui.so.4 #37 0xb71aab35 in QApplication::x11ProcessEvent () from /usr/lib/libQtGui.so.4 #38 0xb71d57ea in ?? () from /usr/lib/libQtGui.so.4 #39 0xb5fff6f8 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0 #40 0xb6002da3 in ?? () from /usr/lib/libglib-2.0.so.0 #41 0xb6002f61 in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0 #42 0xb6cc6478 in QEventDispatcherGlib::processEvents () from /usr/lib/libQtCore.so.4 #43 0xb71d4ee5 in ?? () from /usr/lib/libQtGui.so.4 #44 0xb6c9a52a in QEventLoop::processEvents () from /usr/lib/libQtCore.so.4 #45 0xb6c9a6ea in QEventLoop::exec () from /usr/lib/libQtCore.so.4 #46 0xb6c9cda5 in QCoreApplication::exec () from /usr/lib/libQtCore.so.4 #47 0xb713a767 in QApplication::exec () from /usr/lib/libQtGui.so.4 #48 0xb80cf2bb in kdemain (argc=1, argv=0xbfff1794) at /home/kde4/kde/src/kdesdk/kate/app/katemain.cpp:250 #49 0x080486b6 in main (argc=) at /home/kde4/kde/build/kdesdk/kate/app/kate_dummy.cpp:3 #0 0xb80ef430 in __kernel_vsyscall ()
In release mode, also the second snippet seems to trigger Q_ASSERT(false); in kateviewinternal:329 - which appears in the first backtrace, too. The corresponding kDebug output (never printed due to the assert) says "WARNING: could not find a lineRange at all" Hopefully you can make some sense out of it :D
Oh, and if you want to test: the plugin is in SVN, http://websvn.kde.org/trunk/playground/devtools/kte_autobrace/ Hope you like it!
The crash is still there - and occurs because the View's layout cache is not updated, as the edit stack in editEnd() is not gone yet when textInserted() is emitted. I was able to work around this though, and AutoBrace finally works nice due to splitting the insertion part out into the textChanged() signal which is called after the layout cache is updated (from within editEnd()). So this issue is now irrelevant for me as the new split approach works better on all fronts (not only this crash but other niceties too). I'm keeping the bug open because the crash is not yet fixed, but it's up to you to decide whether that's intended or not, and whether to close this bug because of that or leave it open.
Might be related to bug #171027, but this needs to be tested.
Jakob, can you please test again with current trunk?
Any news?
Closing this, until we get again problems.
Dear Bug Submitter, This bug has been in NEEDSINFO status with no change for at least 15 days. Please provide the requested information as soon as possible and set the bug status as REPORTED. Due to regular bug tracker maintenance, if the bug is still in NEEDSINFO status with no change in 30 days, the bug will be closed as RESOLVED > WORKSFORME due to lack of needed information. For more information about our bug triaging procedures please read the wiki located here: https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging If you have already provided the requested information, please set the bug status as REPORTED so that the KDE team knows that the bug is ready to be confirmed. Thank you for helping us make KDE software even better for everyone!
Dear Bug Submitter, This bug has been in NEEDSINFO status with no change for at least 30 days. The bug is now closed as RESOLVED > WORKSFORME due to lack of needed information. For more information about our bug triaging procedures please read the wiki located here: https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging Thank you for helping us make KDE software even better for everyone!