hzeller / rpi-rgb-led-matrix

Controlling up to three chains of 64x64, 32x32, 16x32 or similar RGB LED displays using Raspberry Pi GPIO
GNU General Public License v2.0
3.67k stars 1.17k forks source link

OverflowError: can't convert negative value to size_t #795

Open northwarks opened 5 years ago

northwarks commented 5 years ago

Hi Guys -I'm having issues with SetImage(), I can display text with no issues at all, as soon as I try to add an image I get the following error:

  File "matrix_v2.py", line 134, in DisplayUpdate
  mycanvas.SetImage(image, 0, 0)
  File "core.pyx", line 22, in rgbmatrix.core.Canvas.SetImage
  File "core.pyx", line 46, in rgbmatrix.core.Canvas.SetPixelsPillow
  OverflowError: can't convert negative value to size_t

I'm calling DisplayUpdate() from a thread every second, no other thread or function is writing to the matrix. I'm a little unsure if I'm actually understanding the correct way of implementing images but I've tried for hours and it always boils down to the OverflowError: can't convert negative value to size_t error despite PIL reporting the image as 50x50 RGB.

  def DisplayUpdate(self):
    mycanvas = self.matrix.CreateFrameCanvas()
    #local_weather={'mylocal_temp': None, 'mylocal_humid': None, 'mylocal_status': None, 'mylocal_icon': None}
    #local_time={'curr_day': None, 'curr_time': None, 'curr_sec': None}
    _sec = local_time.get('curr_sec')
    _day = local_time.get('curr_day')
    _time = local_time.get('curr_time')
    _temp = local_weather.get('mylocal_temp')
    _humid = local_weather.get('mylocal_humid')
    _status = local_weather.get('mylocal_status')
    _icon = local_weather.get('mylocal_icon')
    mycanvas.Clear()
    graphics.DrawText(mycanvas, self.font1, 10, 20, self.blue, _sec)
    graphics.DrawText(mycanvas, self.font3, 34, 40, self.blue, _day)
    graphics.DrawText(mycanvas, self.font1, 38, 30, self.blue, _time)
    graphics.DrawText(mycanvas, self.font3, 3, 60, self.blue, _temp)
    graphics.DrawText(mycanvas, self.font3, 55, 60, self.blue, _humid)
    graphics.DrawText(mycanvas, self.font3, 100, 60, self.blue, _status)
    image = Image.open(_icon)
    image = image.convert('RGB')
    image.load()
    mycanvas.SetImage(image, 1, 1)

Any pointers or skeleton code would be really appreciated :)

hzeller commented 5 years ago

it looks like you are createing a FrameCanvas every time you call DisplayUpdate ? This will allocate a new frame every time so you will run out of memory.

You should only create a frame canvas once, then swap on vsync.

As with the size_t error: can you figure out where that message is coming from ? It looks like somewhere from the inside of the generated Python-wrapper.