Skip to content

Segmentation Fault when using this Library to take a screenshot #4

@wenmana

Description

@wenmana

I was using the following code to take a screenshot:

using XCBased, FileIO, ColorTypes

x11_display = ENV["DISPLAY"]
conn = xcb_connect(x11_display)
setup = get_setup(conn)

screen = setup.screens[1]
width = screen.width_in_pixels
height = screen.height_in_pixels
root = screen.root

output_format = XCB_IMAGE_FORMAT_Z_PIXMAP
plane_mask = 2^32 - 1

rep = xcb_get_image(conn, output_format, root, 0, 0, width, height, plane_mask, checked = false)

reply = fetch(rep)

img_data = reply.data

img = Array{Any}(zeros(height, width))

for i in 1:length(img_data)/4
	# The next line is the one causing problems
	img[Int(ceil(i/width)),Int((4i%width)/4)+1] = RGBX(img_data[Int(4(i-1)+1)]/255, img_data[Int(4(i-1)+2)]/255, img_data[Int(4(i-1)+3)]/255)
end

save("./image.png", img)

xcb_disconnect(conn)

but got a segmentation fault:

signal (11): Segmentation fault
in expression starting at /home/wali/Documents/julia/xshot.jl:23
getindex at ./array.jl:805
unknown function (ip: 0x7faebf2cf9d6)
top-level scope at /home/wali/Documents/julia/xshot.jl:24
unknown function (ip: 0x7faf4635db5f)
unknown function (ip: 0x7faf4635e46c)
jl_toplevel_eval_in at /usr/bin/../lib/julia/libjulia-internal.so.1 (unknown line)
unknown function (ip: 0x7faf342cb837)
unknown function (ip: 0x7faf34302d33)
unknown function (ip: 0x7faf340f70f2)
unknown function (ip: 0x7faf3403bc3d)
unknown function (ip: 0x7faf3403cc6a)
unknown function (ip: 0x7faf3403cdb5)
unknown function (ip: 0x7faf46380ade)
repl_entrypoint at /usr/bin/../lib/julia/libjulia-internal.so.1 (unknown line)
main at julia (unknown line)
__libc_start_main at /usr/bin/../lib/libc.so.6 (unknown line)
_start at julia (unknown line)
Allocations: 10511937 (Pool: 10510873; Big: 1064); GC: 6
[1]    52961 segmentation fault (core dumped)  julia xshot.jl

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions