All-in-one-no-pm.py crashes after 4 hours

After 4 hours:
free(): invalid pointer
Backend terminated or disconnected. Fatal Python error: Aborted
file "/usr/local/lib/python3.7/dist-packaged/ST7735-0.0.3-py3.7.egg/ST7735/init.py, line 212 in send

The actual code line is self.spi.xfer(data[start:end])
inside the def send(self,data, is_data=True, chunk_size=4096):

I’d guess that somewhere the garbage collection or release of a data buffer isn’t being done and eventually the free() fails because somewhere else the data was never allocated.
Pi 3B, Raspian Linux 10 (buster) running Pi under Thonny.

Suggestions?

1 Like

Hi @jcdammeyer, you’re not alone. My APA102 RGB-LED-driving Raspberry Pi project was consistently crashing after 46 hours of running, with a mysterious error:

** Error in `venv/bin/python': free(): invalid pointer: 0x00403eb0 ***

It was with a framerate of 25 frames per second (driving 300 LEDs). When the framerate was set to max, the program died after 7 hours. So it became clear that it is somehow related to the density of SPI communication. Commenting out the spi.xfer() call sort of solved the problem, but, alas, the whole point of the project is to send the SPI data. Pi 3B (Rev 1.2), Raspbian 9 (stretch) here.

Not sure how to fix this. Did you manage to solve it?

Unfortunately not. RIght now the PiZeroW with the envro+ is sitting on the bench in a corner collecting dust. My intention is at some point to rewrite all the software using Lazarus. Write once compile for anywhere. This type of problem, with a system either crashing or resetting I’ve also run into with the ESP8266 and the Arduino development tools. In that case the system runs LED light shows out to strings of RGB LEDs and after a few hours just resets. And no facilities to install a breakpoint on fault. I do get a message that it died. Although the frozen lights is a pretty good clue.

For now I wouldn’t recommend the all in one module.

Is the spidev development abandoned? Such a nasty bug could get a fix sometime soon, no? For now, I’ll be looking for a bitbanging solution.

This is Python SPI right? I did a project a while back where I found Python just wasn’t fast enough to bring in queued CAN messages from a PIC32 connected to a vehicle CAN bus. The client wanted CAN messages logged from Power Up and a Pi takes at least 18 seconds to boot. Once the CAN messages were logged and the Pi was alive I made it the SPI master to transfer the time stamped logged messages from the PIC32 at 10Mbps.

The code was eventually done in C instead of Python. When I’m finished my current set of projects and can get back to the enviro+ I’ll toss out the Python and redo it in either C or Lazarus.

Yes, it’s a Python library. In my case, I care only for outgoing data, so it’s fine.
I must check, maybe it it fine to write directly to /dev/spidev0.1 virtual device file. That would save a lot of hassle. I’ll report back here for the benefit of others.

I have had the same problem with combined.py. I was running with version 0.0.2 of enviroplus, current is 0.0.3. Upgrading enviroplus, was my first thought, but I also checked the pip3 installed components to see if anything there was out of date:
sudo pip3 list --outdated
this list included ST7735 version 0.0.3 -> version 0.0.4, which I believe is the library that puts text onto the 0.96" display and gets called each loop and possibly the actual cause of the memory fault.

WARNING - the next bit took some time and it may have been faster to re-image and start again, but it was a learning experience.

However, I upgraded everything I could, but some items had dependencies and I had to go around more than once. I have saved (some of you) that problem, as I have listed the dependencies I came across below. I also found that numpy had a problem, in that version 1.18.2 complains about missing file, but I found the same problem and solution to this in numpy issue 15890:
https://github.com/numpy/numpy/issues/15890

I found references on how to upgrade pip3 modules at :
https://stackoverflow.com/questions/5183672/how-do-i-update-a-python-package

but because it mentions roll back, I saved the outdated items to a file and ran the upgrade one at a time with the following bash command(s):
python3 -m pip install --upgrade pip
sudo pip3 install --upgrade wheel
sudo pip3 list --outdated > pip3_list
for x in $(nawk ‘{print $1}’ pip3_list | grep -v -E “Package|----”);
do
sudo pip3 install --upgrade $x;
done

If you have cryptography, PyGObject and Pillow requiring upgrade (as I did), the following was also run:
sudo python3 -m pip install --upgrade Pillow
sudo apt-get install build-essential libssl-dev libffi-dev python3-dev
sudo apt install libglib2.0-dev
sudo apt install libgirepository1.0-dev
sudo apt install libcairo2-dev
sudo python3 -m pip install --upgrade PyGObject

Running Raspbian Buster on Pi Zero, updated with apt as of yesterday. All working, but text wonky - need to change code to use integer division in “display_everything” - i.e. replace “/” with “//”.

tested same code running for 19 hours and still working. Hope this helps.

My solution was to re-image. I first did it on a Pi4 with 16GB SD card and full desktop version. Step by step following instructions on pimoroni web page. That ran for a day without issues. I then removed the log statement to get rid of the text and that ran without incident.

I then recreated the command line Raspian from the same install onto a 4GB SD card. This one took much longer to install all the libraries etc. after the usual update upgrade sequence. It also ran with continuous print statements for over one day. Now it’s been running for almost 24 hours with the log statement commented out and in the background with ‘&’ at the end of the text line. Also still running.

What amazes me is that people use Python at all. What a lot of extra crap in there just to get a simple program running. When I get a chance I’m going to rewrite the demos software in Lazarus so I have full control over what is going on.

I’ll make that available when it’s done.