Export a file via a third party PDF printer causes a crash
Nightly 0bd0092 / Windows7
1) Open this file: test file.mscz
2) File -> Print
3) Choose a PDF printer, e.g. PDFCreator -> Print
Result: crash
-This Nightly on May 5 works: 151c717
- Not the followed on May 6: 499ea8e
Remark: on last update of PDFCreator (2.1)
Comments
Confirmed, with 0bd0092 and CC PDF Converter, also Windows 7 (Enterprise, 64bit)
Trying to catch it with debugger was unsuccessful, it just hung.
Could also be due to https://bugreports.qt.io/browse/QTBUG-44349
A build with a snapshot of Qt could help to see if it's the case.
Qt 5.4.2 RC should be available (http://download.qt.io/snapshots/qt/5.4/5.4.2/2015-05-04_132/), final version planned for 'later this month'
I managed to reproduce with 0bd0092 under Windows 8.1 and CutePDF Writer.
Attached the gdb log.
The crash is caused by a division by 0.
And that seems caused by devicePixelRatio() returning 0 (or something less than 1 as actually that function returns a Qreal, not an int, so truncation would occur?), in libmscore/sym.cpp, line 5204:
int pixelRatio = painter->device()->devicePixelRatio();;
This really makes me wonder where compiler warnings are when you need them...
See https://github.com/musescore/MuseScore/pull/1998
This solves the crash, but at least with CC PDF Printer the resulting PDF doesn't look good, all glyphs are missing (cleft, key and time sig, note heads...). I know I had the same issue with Adobe's PDF printer in the past, but seem to remember that CC PDF Printer worked back then?
I don't think that the problem is simply a casting into int.
I think that the device ( painter->device() ) is not set properly, but I don't understand what has changed with respect to the code before the switch to FreeType.
Before FreeType the pixelRatio in the CutePDF Writer case was 1 (I tried with 151c717 Windows 8.1), but this parameter was not used in the code.
Well, als I can say is that changing that one line to
qreal pixelRatio = painter->device()->devicePixelRatio();
fixed the crash
Hmm, strange enough http://doc.qt.io/qt-5/qpaintdevice.html#devicePixelRatio does indeed return int, but http://doc.qt.io/qt-5/qscreen.html#devicePixelRatio, http://doc.qt.io/qt-5/qwindow.html#devicePixelRatio and http://doc.qt.io/qt-5/qguiapplication.html#devicePixelRatio return qreal
Changed it back to int, but also checked whether devicePixelRatio() return 0 and set pixelRatio to 1 in that case.
→ No crash and the resulting PDF looks OK!
No idea though why devicePixelRatio() sometimes return a 0
fixed in 7fbf11fd
Seems Werner fixed it in 89d455f and/or 3e383af and/or 1fbf11f (not really sure which, all touch the same code and I only tried after the last of these)
I see many of the following though now:
Warning: QPrinter::metric: Invalid metric command (:0, )
Automatically closed -- issue fixed for 2 weeks with no activity.