-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xournalpp crashes when including a PNG picture after Cairo update 1.18.0 -> 1.18.2 #5847
Comments
I have encountered the same crash with the PDF export, but it does not occur for every file. I have not yet been able to identify the conditions under which it reproduces. |
You may be able to reproduce this by doing the following:
|
I get the same error when exporting .xopp to pdf |
In my experience, exporting annotated pdf files containing images with embedded fonts crashes xournal when cairo-1.18.2 is installed. Here's why on an example: My beamer example (the included file
On the contrary:
Moreover, if
can likewise be compiled, annotated and exorted to img-NO-fonts.pdf Tne pixelized |
Seems to be related #5820. |
Using openSUSE and libcairo2 1.18.2 from GNOME:Factory or GNOME:Next, I am able to reproduce the PDF export issue, but not the PNG inclusion one. Here's a minimal reproducible code that causes the error, similar to https://www.cairographics.org/cookbook/renderpdf/: #include <iostream>
#include <filesystem>
#include <cairo-pdf.h>
#include <glib-2.0/glib.h>
#include <poppler-document.h>
#include <poppler-page.h>
int main ()
{
// open PDF using poppler
auto uri = g_filename_to_uri(std::filesystem::absolute("in.pdf").c_str(), nullptr, nullptr);
auto document = poppler_document_new_from_file(uri, nullptr, nullptr);
g_free(uri);
// create pdf rendering surface and target
auto surface = cairo_pdf_surface_create("out.pdf", 0, 0);
auto cr = cairo_create(surface);
// render pages one by one
auto num_pages = poppler_document_get_n_pages(document);
for (int i = 0; i < num_pages; ++i) {
auto page = poppler_document_get_page(document, i);
double width, height;
poppler_page_get_size(page, &width, &height);
cairo_pdf_surface_set_size(surface, width, height);
cairo_save(cr);
poppler_page_render_for_printing(page, cr);
cairo_restore(cr);
cairo_show_page(cr);
g_object_unref(page);
}
g_assert(cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS); // no error yet
cairo_surface_finish (surface);
auto status = cairo_surface_status(surface);
if (status) {
std::cerr << cairo_status_to_string(status); // outputs "out of memory"
}
// clean up
cairo_destroy(cr);
cairo_surface_destroy (surface);
g_object_unref(document);
return 0;
} Using a PostScript surface instead of a PDF surface still works. It looks like an upstream regression to me. |
same here, downgrading to |
Thanks for reporting the issue to upstream, @tmoerschell . |
@tmoerschell: Can you please take a look? Thanks in advance for your time and attention! |
Yes, I can also confirm this bug has been fixed upstream. However, release might take a while. Since it is an external dependency, there is nothing we can merge on the xournalpp side. To build cairo yourself:Install build dependencies: from cairo's README:
Or check what the git clone https://gitlab.freedesktop.org/cairo/cairo.git
cd cairo
mkdir build
meson setup --prefix=/usr --buildtype=release build
ninja -C build
sudo ninja -C build install @tjavdar does this also fix the PNG inclusion issue? I wasn't able to reproduce it. |
@tmoerschell: Thanks for the immediate response!
May be the latter is not a Cairo problem whatsoever. Or because I run xournal++ natively under Wayland (stock Arch-package 1.23.1-1) on Hyprland (hyprland-git 0.43.0.r22.d35e70a8-1)? (Still, I don't think that it's Hyprland's fault. This crash persists throughout both the stable Artch package, as well as 10-ish git revisions. Can test it under Wayland/Sway or X/i3 if you think this is a good idea). Enclose the specific PDF and PNG (produced from same metapost source). |
I'm curious, I don't think it is possible to include a PDF as an image. Do you mean opening the PDF directly for annotation? |
@tmoerschell: Thanks again; Here are direct answers to your questions:
I attach for your convenience a zip of both the xopp-file, the PNG, the ePDF, as well as the metapost source they are produced from. |
Hi, thank you very much for the precision and availability. I still couldn't directly find out what is wrong. The image loading code might have one or two issues, but I can't understand why it'd crash for a simple PNG under 4096 bytes. xournalpp/src/core/model/Image.cpp Lines 76 to 98 in ed37b0b
buffer is useless, and if a second pass of the loop should happen, the same data is sent again from the beginning.
If you're up for it, could we maybe try something so that we can find out what is happening remotely? I wrote the image loading / format determination part as a standalone, with better error checking. Compile and execute the following, with your file name as argument: main.cpp.txt mv main.cpp.txt main.cpp
g++ -o load-image $(pkg-config --cflags --libs gdk-pixbuf-2.0) main.cpp
load-image _Partition1.png What is the output? On success, you should get:
Can you find images that make it fail and others that don't? If you modify line 55 of the source as stated in the comment right above it and recompile, are there any differences? As you can see in the source, cairo is not used for this specific part of the code, I'd be really surprised if the cairo version makes a difference in the standalone. This whole thing puzzles me. |
@tmoerschell: If God is nice, we might not have to get that far. Sorry to tell you that (you've spent time to distill that that standalone), but C++ Vaguely remembering that the same PDF/PNG generated with inscriptions Success part:Here comes the mystic successful part: Amazingly enough, updating to stock Arch package I prepared from the same source 3 Figs (in dir Crash part:As a Maths teacher I'm mostly annotating LaTeX Beamer presentations, often with And Bingo, here came the font-no-font cairo export divide. I prepared (LaTeX-sources in ./LaTeX-dir): All above references in the uppdated: |
Thank you again for all the details. The fact that exporting some PDFs does not work with cairo-1.18.2 is "expected". By installing version 1.18.2, you reverted the fix that was done on the latest build (b9eed915f). So if I understand this right, the image inclusion crash happens on the self-built package, but not on those from the distribution? Or not anymore at all? Is the "stock Arch package PS: You can use |
@tmoerschell: I will probably have to apologize for your time and effort, now that things seem to work well with newest cairo-git. Yes, I did revert to stock Arch Cairo 1.18.2-1 when doing all experiments of pure curiosity. And yes, it might have been updated in the recent 2-3 days, I realy don't know. (Switching between stock versions of cairo is not a problem, as well as installing cairo-git from AUR using yay is a breeze). Good News under newest
|
No need to apologize, I'm happy to hear it finally works for you. If everything is working fine, I think this issue can be closed. I whish you all the best with Xournal++! |
Yes, Still, I cannot help the feeling some black magic took place behind the scences (some random Arch package got uppdated or something). Thanks again everybody! |
@tmoerschell : for me the issue happens on the current flatpak version |
@kostat you need to install the latest build of cairo. You can either build it yourself as described above: #5847 (comment) Or you might be able to find a packaged nightly build such as cairo-git or similar for your distribution. |
@tmoerschell , you understand that your suggestion may work only with xournallpp installed natively. The flatpak version uses a bundled cairo. |
Ok I understand. I'm a little out of my depth when it comes to flatpaks. I'm not sure how this would need to be specified in the flatpak manifest, but you could open an issue on the corresponding flathub repo. If you feel confident enough, you could as well try to build the flatpak package yourself. |
The Xournal++ flatpak uses the Gnome runtime which in turn is based on the Freedesktop runtime. The Cairo version in used is defined there: https://gitlab.com/freedesktop-sdk/freedesktop-sdk/-/blob/master/elements/components/cairo.bst?ref_type=heads |
Operating System
Linux
(Linux only) Distribution
Arch
(Linux only) Desktop Environment
i3
(Linux Only) Display Server
None
Installation Method
xournalpp-git 1.2.3.r335.g2e9c84a88-1
Xournal++ Version
xournalpp 1.2.3+dev (2e9c84a)
libgtk Version
libgtk: 3.24.43
Bug Description
Manifestation when including PNG images:
After a regular upgrade of the cairo package on Archlinux,
I cannot longer include PNG images in xournalpp. It crashes with error message:
The PNG images are just several kB in size, created by ImageMagic, typically, 200 x 126, 8-bit grayscale, non-interlaced,
After downgrading Cairo back to version
1.18.0-2
the problem disappears.Expected Behaviour
Xournalapp not to crash when icluding png images even with the newest stable Cairo release.
This is probably a Cairo bug, but I don't know how to show it directly.
Steps to Reproduce
cairo-1.18.2-1
instaledAdditional Context
Manifestation when converting annotated LaTeX presentations to pdf
I usually annotate LaTeX Beamer presentations converted to pdf. These usually include pictures in PNG or epdf inside,
After updating cairo to 1.18.2, I can still annotate w/o problem, but cannot longer export the annotation to pdf. If the original LaTeX presentation is in
A.pdf
, annotation is inA.xopp
and the exported annotated pdf is to beA-annot.pdf
, then either using theFile->Expot as PDF
or running on the command linecrashes with error message:
Again, after downgrading Cairo back to version
1.18.0-2
the problem disappears.The text was updated successfully, but these errors were encountered: