Clemapfel / Mousetrap.jl

Finally, a GUI Engine made for Julia
https://clemens-cords.com/mousetrap
GNU Lesser General Public License v3.0
410 stars 10 forks source link

Setting a .jpg as texture segfaults #67

Open LilithHafner opened 9 months ago

LilithHafner commented 9 months ago

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.

Clemapfel commented 9 months ago

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 commented 9 months ago

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.

LilithHafner commented 9 months ago

Ah, yes. A classic.