jgarff / rpi_ws281x

Userspace Raspberry Pi PWM library for WS281X LEDs
BSD 2-Clause "Simplified" License
1.77k stars 620 forks source link

Segmentation fault when calling ws2811_fini #284

Open natcl opened 6 years ago

natcl commented 6 years ago

There seems to be a segmentation fault when calling ws2811_fini in the nodejs bindings. Any tips on how to fix that ?

Thanks !

void finalize(const Nan::FunctionCallbackInfo<v8::Value> &info)
{
  ws2811_return_t ret;

  ret = ws2811_wait(&ws281x);
  if (ret != WS2811_SUCCESS)
  {
    Nan::ThrowError(ws2811_get_return_t_str(ret));
    return;
  }

  ws2811_fini(&ws281x);
}
danielytics commented 6 years ago

I’ve noticed the same thing a few days ago, while using C++ (but not while using the included test program, which is odd because my code was based off it).

Gadgetoid commented 6 years ago

I think this is related, ws2811_fini was removed from the Python bindings, but it turns out there may be a memory leak remaining: https://github.com/jgarff/rpi_ws281x/commit/d4c7e35cd511d8c784c36d0f935fb6fb9f01364a

Looks like the segfault has been swept under the rug somewhat, and we should probably track it down and correct it. I suspect it's due to ws2811_fini attempting to clean up things which haven't been allocated.

https://github.com/jgarff/rpi_ws281x/blob/d50cc444fa3a12bd8e2332ac5d1dd5e61b338e68/ws2811.c#L1061-L1079

etanx commented 6 years ago

This may be slightly different, but when I run any of the python example scripts I get:

File "build/bdist.linux-armv6l/egg/neopixel.py", line 102, in begin RuntimeError: ws2811_init failed with code -1 Segmentation fault

I could get an older x16 RGB LED ring to work, but now with a x24 RGBW (I used a branch sk6812) it's not initializing.

davthomaspilot commented 6 years ago

Check out the issue I just posted. Try intializing .chan[0].gamma and chan[1].gamma to zero.