2

I am programming code to display camera feed with my raspberry pi 3 and Raspbian. Strangely, sometimes the code shows the video and sometimes i get the Segmentation fault error. I used gdb to find more about the error. This was the output:

Starting program: /usr/bin/python3 qt.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
[New Thread 0x720a7470 (LWP 20003)]
[New Thread 0x716ff470 (LWP 20004)]

** (python3:19975): WARNING **: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files
[New Thread 0x6ff00470 (LWP 20007)]
[New Thread 0x6f5ff470 (LWP 20008)]
[New Thread 0x6e6ab470 (LWP 20022)]
[Thread 0x6e6ab470 (LWP 20022) exited]
[New Thread 0x6e6ab470 (LWP 20023)]
[Thread 0x6e6ab470 (LWP 20023) exited]
Venus USB2.0 Camera
[<PyQt5.QtMultimedia.QCameraInfo object at 0x72fde030>]
Capturemode supported

Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
0x7344b620 in platform_get_handle () from /opt/vc/lib/libEGL.so

I read that it can happen that you run out of memory. Is there a solution to my problem? here is more debug code for your enjoyment:

(gdb) bt
#0  0x733d4620 in platform_get_handle () from /opt/vc/lib/libEGL.so
#1  0x733c9f2c in eglCreateWindowSurface () from /opt/vc/lib/libEGL.so
#2  0x722e7004 in ?? ()
   from /usr/lib/arm-linux-gnueabihf/qt5/plugins/xcbglintegrations/libqxcb-egl-integration.so
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Also here is my code:

import sys
import traceback
import logging
from PyQt5 import QtCore , QtWidgets, QtGui, QtMultimedia, QtMultimediaWidgets
from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import QApplication, QPushButton, QMainWindow
from PyQt5.QtMultimedia import QCamera, QCameraInfo, QMediaObject, QCameraViewfinderSettings, QCameraImageCapture
from PyQt5.QtMultimediaWidgets import QCameraViewfinder


class Camera(QObject):
    def __init__(self, parent = QObject()):
        super(Camera, self).__init__(parent)
        self.cam = QCamera()
        self.caminfo = QCameraInfo(self.cam)
        self.camvfind = QCameraViewfinder()
        self.camvfindset = QCameraViewfinderSettings()
        self.cammode = self.cam.CaptureMode(1)
        self.camimgcap = QCameraImageCapture(self.cam)

    def iniCamera(self):
        print(self.caminfo.description())
        print(self.caminfo.availableCameras())

        if self.cam.isCaptureModeSupported(self.cammode):
            print("Capturemode supported")


    def startVid(self):


        self.camvfind.show()

        self.cam.setViewfinder(self.camvfind)

        #self.cam.load()
        #self.camvfindset.setResolution(1280,720)
        #print(self.cam.supportedViewfinderFrameRateRanges(self.camvfind))
        #self.camvfindset.setMinimumFrameRate(15)

        self.cam.setCaptureMode(self.cammode)
        self.cam.start()



if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)

    cam = Camera()

    cam.iniCamera()

    try:
        cam.startVid()
    except Exception as error:
        logger.debug(traceback.format_exc())

    sys.exit(app.exec_())
  • Those times when you can display video, what is the memory load on the system? It's unlikely to be memory dependent. Most likely there is a race condition in some of the modules you load and someone accesses memory before someone else has set it up. It looks like the program is looking for a handle in libEGL and that function is triggering the segfault. Unfortunately this likely has nothing to do with your python program or python code. – crasic Nov 23 '17 at 17:54
  • I know its lame and unusual for python code, but I would sprinkle delays (100ms or so) between constructor (cam= Camera()) , iniitialization (cam.iniCamera()) and start of video (cam.startVid()) . This is a simple trick to prove a low level race condition you may be hitting (by starting video before camera has iniitialized) – crasic Nov 23 '17 at 18:07
  • do you recommend anything to show the memory load? Unfortunately using delays did nothing. I tried to install some packages for checking memory in a python code but i just get errors or its not supported for python3 – Xenoshell Nov 27 '17 at 8:57
  • Ok i tried the memory check with psutil. Output before the segmentation fault is 49385472 bytes. And if the error happens i cant see the output after segmentation fault. However if the code actually shows the camera feed before is 49528832 bytes and after the camera feed is 52858880. I am starting to think that if the before-bytes are over a certain point. It is too much and the segmentation fault will happen – Xenoshell Nov 27 '17 at 10:52
  • Your error is /opt/vc/lib/libEGL.so so it's unclear if your camera code is related to a crash you're getting in rendering code (QtWindow), and whether the crash you get in gdb is the same as the one when running live. This is the older Broadcom driver, but Qt can work with the newer Mesa libs. If you run sudo raspi-config and install the full OpenGL, it should at least use /usr/lib/arm-linux-gnueabihf/libEGL.so instead. Try that and see if the error looks different? – jdonald Nov 27 '17 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.