Avoid segfault on loading images#1
Conversation
There was a problem hiding this comment.
Where exactly does it crash?
It shouldn't be crashing in dynamic_cast, as dynamic_cast()ing a null pointer is legal:
http://stackoverflow.com/questions/5155820/portably-safe-to-pass-null-zero-to-dynamic-cast
There was a problem hiding this comment.
All I know is that it crashed in this line (after opening a directory for loading images) and my fix fixed it.
There was a problem hiding this comment.
Ok it's when I close the project data dialog
#0 0x0000000000000000 in ?? ()
#1 0x0000000000759ff8 in __cxxabiv1::__dynamic_cast (src_ptr=0x80d637900,
src_type=0x802c07348 <typeinfo for QGraphicsItem>,
dst_type=0xbb4340 <typeinfo for IncompleteThumbnail>, src2dst=0)
at ../../.././../gcc-4.8.5/libstdc++-v3/libsupc++/dyncast.cc:72
#2 0x0000000000458d5a in ThumbnailSequence::CompositeItem::incompleteThumbnail
(this=0x80d6c7280)
at /data/compile/scantailor/Tulon/scantailor/ThumbnailSequence.cpp:1563
#3 0x00000000004584e7 in ThumbnailSequence::Item::Item (this=0x7fffffffcb40,
page_info=..., comp_item=0x80d6c7280)
at /data/compile/scantailor/Tulon/scantailor/ThumbnailSequence.cpp:1435
#4 0x0000000000453e77 in ThumbnailSequence::Impl::reset (this=0x80d464f40,
pages=..., selection_action=ThumbnailSequence::RESET_SELECTION,
order_provider=...)
at /data/compile/scantailor/Tulon/scantailor/ThumbnailSequence.cpp:543
#5 0x000000000045355c in ThumbnailSequence::reset (this=0x80d52bb40,
pages=..., selection_action=ThumbnailSequence::RESET_SELECTION,
order_provider=...)
at /data/compile/scantailor/Tulon/scantailor/ThumbnailSequence.cpp:365
#6 0x000000000048221f in MainWindow::resetThumbSequence (this=0x80d512300,
page_order_provider=...)
at /data/compile/scantailor/Tulon/scantailor/MainWindow.cpp:662
#7 0x0000000000480b50 in MainWindow::switchToNewProject (this=0x80d512300,
pages=..., out_dir=..., project_file_path=..., project_reader=0x0)
at /data/compile/scantailor/Tulon/scantailor/MainWindow.cpp:425
#8 0x00000000004857a9 in MainWindow::newProjectCreated (this=0x80d512300,
context=0x80d74b830)
at /data/compile/scantailor/Tulon/scantailor/MainWindow.cpp:1375
#9 0x00000000004a15a9 in MainWindow::qt_static_metacall (_o=0x80d512300,
_c=QMetaObject::InvokeMetaMethod, _id=26, _a=0x7fffffffd060)
at /data/compile/scantailor/Tulon/scantailor/moc_MainWindow.cpp:232
#10 0x000000080387a37a in QMetaObject::activate(QObject*, int, int, void**) ()
from /usr/local/lib/libQt5Core.so.5
#11 0x00000000004a1e27 in ProjectCreationContext::done (this=0x80d74b830,
_t1=0x80d74b830)
at /data/compile/scantailor/Tulon/scantailor/moc_ProjectCreationContext.cpp:150
#12 0x000000000044be4f in ProjectCreationContext::projectFilesSubmitted (
---Type <return> to continue, or q <return> to quit---
this=0x80d74b830)
at /data/compile/scantailor/Tulon/scantailor/ProjectCreationContext.cpp:52
#13 0x00000000004a1bfc in ProjectCreationContext::qt_static_metacall (
_o=0x80d74b830, _c=QMetaObject::InvokeMetaMethod, _id=1, _a=0x7fffffffd200)
at /data/compile/scantailor/Tulon/scantailor/moc_ProjectCreationContext.cpp:83
#14 0x000000080387a37a in QMetaObject::activate(QObject*, int, int, void**) ()
from /usr/local/lib/libQt5Core.so.5
#15 0x00000008027337b5 in QDialog::done(int) ()
from /usr/local/lib/libQt5Widgets.so.5
#16 0x00000000004688ca in ProjectFilesDialog::finishLoadingMetadata (
this=0x80d6baa80)
at /data/compile/scantailor/Tulon/scantailor/ProjectFilesDialog.cpp:600
#17 0x00000000004686b2 in ProjectFilesDialog::timerEvent (this=0x80d6baa80,
event=0x7fffffffda60)
at /data/compile/scantailor/Tulon/scantailor/ProjectFilesDialog.cpp:561
#18 0x0000000803873353 in QObject::event(QEvent*) ()
from /usr/local/lib/libQt5Core.so.5
#19 0x00000008025a7e1a in QWidget::event(QEvent*) ()
from /usr/local/lib/libQt5Widgets.so.5
#20 0x000000080256af7d in QApplicationPrivate::notify_helper(QObject*, QEvent*)
() from /usr/local/lib/libQt5Widgets.so.5
#21 0x000000080256e899 in QApplication::notify(QObject*, QEvent*) ()
from /usr/local/lib/libQt5Widgets.so.5
#22 0x000000000042dfb8 in Application::notify (this=0x7fffffffdea0,
receiver=0x80d6baa80, e=0x7fffffffda60)
at /data/compile/scantailor/Tulon/scantailor/Application.cpp:32
#23 0x0000000803848473 in QCoreApplication::notifyInternal(QObject*, QEvent*)
() from /usr/local/lib/libQt5Core.so.5
#24 0x00000008038993fa in QTimerInfoList::activateTimers() ()
from /usr/local/lib/libQt5Core.so.5
#25 0x000000080389a531 in ?? () from /usr/local/lib/libQt5Core.so.5
#26 0x000000080afdf778 in g_main_context_dispatch ()
from /usr/local/lib/libglib-2.0.so.0
#27 0x000000080afdfaab in ?? () from /usr/local/lib/libglib-2.0.so.0
#28 0x000000080afdfb34 in g_main_context_iteration ()
from /usr/local/lib/libglib-2.0.so.0
#29 0x0000000803899f2b in QEventDispatcherGlib::processEvents(QFlags<QEventLoop:---Type <return> to continue, or q <return> to quit---
:ProcessEventsFlag>) () from /usr/local/lib/libQt5Core.so.5
#30 0x0000000803845cbd in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/local/lib/libQt5Core.so.5
#31 0x0000000803848a18 in QCoreApplication::exec() ()
from /usr/local/lib/libQt5Core.so.5
#32 0x00000000004a02aa in main (argc=1, argv=0x7fffffffe0b0)
at /data/compile/scantailor/Tulon/scantailor/main.cpp:218
There was a problem hiding this comment.
Strange, as with my "fix" the dynamic_cast is called only if m_pThumb is NOT NULL
.. I mean when it IS NULL .. I'm completely confused ..
It crashes when m_pThumb is NOT NULL
If I just "return !m_pThumb;" it seems to work, too
There was a problem hiding this comment.
I wonder if Qt was built with a different compiler or with flags that change vtable format.
Is Scan Tailor from ports affected? If not, check what kind of flags or patches they are applying.
There was a problem hiding this comment.
You know, you could just let FreeBSD scantailor maintainer deal with this problem, given that it's a FreeBSD-specific one. The code in question didn't change for a long time.
I would be extremely surprised if the problem turns out to be related to the use of std::auto_ptr. You are free to pursue this course, but it looks like you need to read some articles on auto_ptr and unique_ptr first. I don't really have time to explain every detail, while you can easily find this information on the web.
There was a problem hiding this comment.
I haven't found out, but seems to work when I cast piecewise like
bool
ThumbnailSequence::CompositeItem::incompleteThumbnail() const
{
ThumbnailBase * thb = dynamic_cast<ThumbnailBase*>(m_pThumb);
return thb != 0 && dynamic_cast<IncompleteThumbnail*>(thb) != 0;
}
There was a problem hiding this comment.
Interesting. So it doesn't crash anymore but is it working correctly? Does it ever return true?
BTW, incomplete thumbnails are those with question marks.
There was a problem hiding this comment.
Apparently it returns 0s and 1s and runs correctly, yes
Hmm now in the master branch I get the next dynamic_cast problem in PixmapRenderer.cpp:70
if (QWidget* widget = dynamic_cast<QWidget*>(paint_dev)) {
(this code is gone with the Qt5 version)
There was a problem hiding this comment.
Looks like something is broken with FreeBSD. Maybe a better idea would be creating a small example reproducing the problem and let FreeBSD developers deal with it.
As for double-casting to IncompleteThumbnail, I would prefer a cleaner solution:
Make ThumbnailFactory return ThumbnailBase rather than QGraphicsItem and add a virtual isIncomplete() method to ThumbnailBase and IncompleteThumbnail.
|
another issue: |
|
Can I have a simple project where it happens? |
|
I'm afraid not, it happened once and I can't reproduce it. I think it happened when changing orientation of some pages to 180° ... |
|
I finally managed to reproduce the failing assertion. It happens when there is no content box at all (it can be removed via a context menu). I'll fix it soon. |
|
Do you know the fix? I ran into it again |
On FreeBSD the program crashes immediately.
Please allow posting issues, as this one would have been much easier