On Thu, May 5, 2016 at 2:10 AM Andrea Giammarchi <
andrea.giammar...@gmail.com> wrote:

> I'm not sure what's going on but I am unable to debug due Segment fault in
> debugging mode.
>
> All I need to do is to scale an image in order to make it fit into a
> dialog (like an image preview)
>
> However, as soon as I
>
> ```gjs
> pixbuf = GdkPixbuf.Pixbuf.new_from_file(validImageAbsPath)
> ```
>
> the CPU reached 100% and there's no way to make it stop.
> I've tried to get rid of the reference count doing this after
>
> ```gjs
> pixbuf = Gtk.Image.new_from_pixbuf(pixbuf.scale_simple.apply(
>             pixbuf,
>             this.calucalteSize(
>               screen,
>               pixbuf,
>               margin
>             ).concat(
>               GdkPixbuf.InterpType.BILINEAR
>             )
>           ));
> ```
> and while the image works, after a little while it's shown the app crashes
> (doing literally nothing else)
>
>
> I've noticed that this does not instantly happen if the image is a small
> one, but as soon as I use 4K images the app crashes each time.
>
> I couldn't find much documentation and all I can guess is that maybe I am
> missing something, like an initialization?
>
> https://developer.gnome.org/gdk-pixbuf/2.34/gdk-pixbuf-gdk-pixbuf-Xlib-initialization.html
>
> Or maybe GdkPixbuf is known to be somehow problematic via GJS (or
> everywhere) ?
>

Hi Andrea,

I've been hoping someone else knows the answer. I do have a guess though. I
have definitely used GdkPixbuf on GJS without this happening, so it is not
broken all the time.

However, there was a bug where SpiderMonkey is unaware of how much memory
the pixbuf has allocated for itself internally. I thought I remembered
someone fixed it in the meantime, but I searched and here it is still open
[1].

The problem is basically that SpiderMonkey has no way of knowing the
GdkPixbuf object is using so much memory, and so it never decides to GC.
This may be what you're running into when you use 4K images.

Are you going to display the images at 4K on screen? If not, then you could
consider GdkPixbuf.Pixbuf.new_from_file_at_size() [2] to reduce the amount
of memory that ever gets allocated. Or, you could get tricky and apply a
Gtk.CssProvider with dynamically generated CSS with background-image:
url('file:///valid/image/abs/path'); to your widget; that way, all the
memory allocation will happen inside the library, in C, where it can be
properly freed.

Regards,
Philip

[1] https://bugzilla.gnome.org/show_bug.cgi?id=630908
[2]
http://docs.ptomato.name:9292/gdkpixbuf20~2.31.6/gdkpixbuf.pixbuf#constructor-new_from_file_at_size
_______________________________________________
javascript-list mailing list
javascript-list@gnome.org
https://mail.gnome.org/mailman/listinfo/javascript-list

Reply via email to