Mousetrap.jl icon indicating copy to clipboard operation
Mousetrap.jl copied to clipboard

Setting a .jpg as texture segfaults

Open LilithHafner opened this issue 1 year ago • 3 comments

This code produces a segfault:

using Mousetrap
main() do app::Application

    window = Window(app)
    set_title!(window, "Issue 67")
    render_area = RenderArea()
    shape = Rectangle(Vector2f(-1, 1), Vector2f(2, 2))

    image = Image("path/to/example.jpg")
    # image = Image("path/to/example.png")

    texture = Texture()
    create_from_image!(texture, image)

    set_texture!(shape, texture)

    add_render_task!(render_area, RenderTask(shape))

    set_size_request!(render_area, Vector2f(500, 500))
    set_child!(window, render_area)
    present!(window)
end

Result:

[216028] signal (11.2): Segmentation fault
in expression starting at /home/x/.julia/dev/battlecode/render_cube.jl:8
__GI_memcpy at /lib64/libc.so.6 (unknown line)
unknown function (ip: 0xffff71482167)
Allocations: 2035102 (Pool: 2033442; Big: 1660); GC: 3
Segmentation fault (core dumped)

Using a .png works around the issue.

LilithHafner avatar Jan 27 '24 14:01 LilithHafner

I can reproduce this, it's a bug in the C++ component. It may take some time to update, as any changes need to be merged with the binary builder build tree. This is a pretty big issue though, thank you for pointing it out.

Clemapfel avatar Feb 08 '24 05:02 Clemapfel

Fixed by https://github.com/Clemapfel/mousetrap/commit/d12ae02c4ec389ff7374c1f6772aa338b19c15b4, it will take some time to go live since it needs to be reviewed by the binary builder people and uploaded to the registry.

If you're curious, it was because some jpg files do not have an alpha channel, but the texture loading assumed it did, so it went too far into memory and segfaulted when loading the image data.

Clemapfel avatar Feb 15 '24 18:02 Clemapfel

Ah, yes. A classic.

LilithHafner avatar Feb 15 '24 21:02 LilithHafner