pappersverk / rpi_fb_capture

Capture the Raspberry Pi's framebuffer
Apache License 2.0
11 stars 2 forks source link

Potential issues with Elixir 1.9 or Nerves 1.5 #2

Closed lawik closed 5 years ago

lawik commented 5 years ago

I had a user get in touch about some issues with our Inky scenic driver which uses this where this module would end up sending a crash message because the port crashed.

I haven't confirmed that this is related to the updates but I figured I'd give a heads up in case you have something off of the top of your head about what might cause such an issue. Otherwise I'll follow up if I get more info.

I received this log:

00:00:52.489 [error] Jan  1 00:00:52 rpi_fb_capture: Unable to open primary display

00:00:52.496 [error] GenServer #PID<0.1566.0> terminating
** (stop) bad return value: {:stop, :port_crashed}
Last message: {#Port<0.187>, {:exit_status, 1}}
State: %RpiFbCapture.State{display_height: 0, display_id: 0, display_width: 0, height: 104, port: #Port<0.187>, request: {{#PID<0.1563.0>, #Reference<0.1665486460.268435457.243310>}, :rgb24}, width: 212}

00:00:52.503 [error] GenServer #PID<0.1563.0> terminating
** (MatchError) no match of right hand side value: {:error, :port_crashed}
    (scenic_driver_inky) lib/scenic_driver_inky.ex:90: ScenicDriverInky.handle_info/2
    (scenic) lib/scenic/view_port/driver.ex:215: Scenic.ViewPort.Driver.handle_info/2
    (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: :capture
State: %{driver_module: ScenicDriverInky, driver_state: %{cap: #PID<0.1566.0>, color_affinity: :low, color_high: 180, color_low: 75, dithering: false, inky_pid: #PID<0.1565.0>, interval: 1000, last_crc: -1, size: {212, 104}, viewport: #PID<0.1548.0>}, viewport: #PID<0.1548.0>}

00:00:52.512 [error] GenServer #PID<0.1564.0> terminating
** (stop) bad return value: {:stop, :port_crashed}
Last message: {:EXIT, #PID<0.1563.0>, {:bad_return_value, {:stop, :port_crashed}}}
State: %{driver_module: Scenic.Driver.Nerves.Rpi, driver_state: %{clear_color: {0, 0, 0, 255}, closing: false, currently_drawing: [], debounce: %{}, dirty_graphs: [], dl_block_size: 128, dl_map: %{}, draw_busy: false, end_dl: nil, fonts: %{}, inputs: 0, last_used_dl: nil, pending_flush: false, port: #Port<0.186>, ready: false, root_ref: nil, screen_factor: 1.0, start_dl: nil, sync_interval: 15, textures: %{}, used_dls: %{}, viewport: #PID<0.1548.0>}, viewport: #PID<0.1548.0>}
fhunleth commented 5 years ago

That's not good. The display width and height look suspicious in the log messages. Maybe a clue?

lawik commented 5 years ago

I got a minimal test-case that seems to confirm it as part of 1.8 -> 1.9 or OTP 21 to 22. https://github.com/pappersverk/scenic_driver_inky/issues/3 I'll take a deeper look if I have a chance.

lawik commented 5 years ago

Clean nerves-project on Erlang 22.0 and Elixir 1.9 OTP 22.

Just added the RpiFbCapture dependency and then I just pushed the firmware and ran from iex:

iex(nerves_hello@nerves.local)1> {:ok, cap} = RpiFbCapture.start_link(width: 5, height: 5, display: 0)
{:ok, #PID<0.1030.0>}
** (EXIT from #PID<0.1028.0>) shell process exited with reason: bad return value: {:stop, :port_crashed}
lawik commented 5 years ago

Ah, RingLogger gave me a bit more story:

00:01:02.000 [error] Jan  1 00:01:01 rpi_fb_capture: Unable to open primary display
fhunleth commented 5 years ago

I can reproduce. I've narrowed it down to the rpi-firmware version update from https://github.com/raspberrypi/firmware. Cherry-picking through releases now...

fhunleth commented 5 years ago

This is the commit that where I start getting "Unable to open primary display": https://github.com/raspberrypi/firmware/commit/64b5649a41b69d09bfe0ed05448d28a66be3edfd.

It could be that there's some setting or something that we need to do now.

fhunleth commented 5 years ago

Apparently it works better with the latest: https://github.com/raspberrypi/firmware/commit/38e81f25e639d19fc0ce6e67fd39998c340a15d5. The "Unable to open primary display" message goes away. There's a scenic error with no info for me now - may be unrelated.

fhunleth commented 5 years ago

Ok, things seem to work. After a clean build the scenic error went away.

I made a nerves_system_br update (v1.8.5) with the fix. You can create a custom nerves_system_rpi0 and bump the version of nerves_system_br in it to get the fix. Or you can wait. I think that it will take a day or two to get new official system releases out.

lawik commented 5 years ago

I'll wait for the release. Good job :)