Skip to content
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

[BUG] cairo-rs context.paint() or fill() not working #661

Closed
wanming opened this issue Apr 26, 2022 · 8 comments
Closed

[BUG] cairo-rs context.paint() or fill() not working #661

wanming opened this issue Apr 26, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@wanming
Copy link

wanming commented Apr 26, 2022

Bug description

context.paint() or fill() not work on alpine linux, the backgroud of the output png is transparent.

but it works fine on macOS or debian.

How to reproduce

download my example code zip, unzip it, and run cd cairo-issue:

cairo-issue.zip

docker run -v $PWD:$PWD -it -w $PWD rust:1.60.0-alpine3.15 /bin/sh

in docker shell:

apk add cairo-dev libc6-compat musl-dev
cargo run

check the output.png in code folder, the background of the output png should be yellow. but it's not.

I'v tried install other packages, like gtk+3.0-dev or gtk4.0-dev, but the results are the same.

appreciate it if you can give me some help, thanks.

@wanming wanming added the bug Something isn't working label Apr 26, 2022
@sdroege
Copy link
Member

sdroege commented Apr 26, 2022

That sounds like something to report to https://gitlab.freedesktop.org/cairo/

@sdroege sdroege closed this as completed Apr 26, 2022
@wanming
Copy link
Author

wanming commented Apr 26, 2022

I tried to run c code on alpine linux, it works fine, the backgroud shows correctly.

So I think it may be a bug of cairo-rs, I'm not sure, here is my c code:

#include <cairo.h>

int main(void)
{
  cairo_surface_t *surface;
  cairo_t *cr;

  surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 390, 60);
  cr = cairo_create(surface);

  cairo_set_source_rgb(cr, 0.0, 1.0, 1.0);
  cairo_paint(cr);

  cairo_surface_write_to_png(surface, "image.png");

  return 0;
}

// gcc t.c -o example `pkg-config --cflags --libs cairo`

@sdroege
Copy link
Member

sdroege commented Apr 26, 2022

  surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 390, 60);

You Rust code uses 100x100

  cairo_set_source_rgb(cr, 0.0, 1.0, 1.0);

Your Rust code uses 1.0 1.0 0.1

If you change them to the same they still behave differently? Are both the C and Rust version linked to the same version of cairo (check with ldd)?

The Rust code is literally just calling those C functions :)

@wanming
Copy link
Author

wanming commented Apr 26, 2022

after changed the args they still behave differently, the backgroud of the image that generated on alpine linux is transparent, here is the images(first image is fully transparent):

Alpine

macOS

"The Rust code is literally just calling those C functions", I know this, But I just can't figure out why 😂 thanks for you time btw, I'll do some more research.

@sdroege
Copy link
Member

sdroege commented Apr 26, 2022

My best guess would be that it's some miscompilation of cairo or so on alpine, or because of alpine using musl

@psychon
Copy link
Contributor

psychon commented May 8, 2022

For the sake of whoever comes across this and wants to find the corresponding cairo issue: https://gitlab.freedesktop.org/cairo/cairo/-/issues/564

@wanming
Copy link
Author

wanming commented May 9, 2022

I finally found out that it should be a problem with rust compilation. It finally works fine after I add an ENV RUSTFLAGS=-Ctarget-feature=-crt-static before cargo build, which means compiling rust code on 'dynamic link' mode(default is static-link, but it's meaningless because I have already used Cairo dynamic link). there should be some bug or strange behavior in rust compilation, I guess.
thanks/sorry for taking your time.

@sdroege
Copy link
Member

sdroege commented May 9, 2022

There's various strangenesses with musl that require such things, yes. See for example rust-lang/rust#82193 , #387 (comment), rust-lang/compiler-team#422 , gtk-rs/gtk3-rs#351 (comment) and many others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants