DesertCarMechanic
DesertCarMechanic

Reputation: 85

`cairo_image_surface_create_from_png` returns "out of memory", but I have enough memory

Note: I am writing my own window manager that is similar to AwesomeWM in that it will be written in C, and have a lua api for customisation.

The problem I'm facing is with this code:

local bg_img = lgi.cairo.ImageSurface.create_from_png("path_to_image.png")
print(bg_img.status) -- This prints "NO_MEMORY"

-- this is part of the window manager api, but I think you can still make out what's going on
local s = tsoil.create(screen_width, screen_height)
s.cr:rectangle(0, 0, screen_width, screen_height)
s.cr:set_source_surface(bg_img)
s.cr:fill()

tsoil.set_as_wallpaper(s)

This code prints out "NO_MEMORY" for some reason. I don't think this should happen, since the image is only about 600kb of memory.

I also tried loading in a much smaller image (26kb in size), and that worked.

I also tried running my window manager with Xephyr, and also directly with startx, but that didn't make my code with the larger image work. I don't know how to fix this.

EDIT: I also tried this in awesome-wm and it also fails. Again, I don't know why.

EDIT2: I also tried to rewrite this code in C, and it still gives the same error:

    // only the code that gives this error, for the sake of brevity
    cairo_surface_t *img = cairo_image_surface_create_from_png(path);
    // this prints "out of memory"
    printf("%s\n", cairo_status_to_string(cairo_surface_status(img)));

Upvotes: 0

Views: 306

Answers (1)

DesertCarMechanic
DesertCarMechanic

Reputation: 85

Nevermind, I found the answer.

I tried loading a ".jpg" image with the cairo ...from_png function, which is my fault.

However, this is not entirely my fault. Cairo should have an error return value that should clearly signify that the file exists, but is not a PNG.

Upvotes: 1

Related Questions