picamera2 icon indicating copy to clipboard operation
picamera2 copied to clipboard

Cannot allocate memory after several times create camera and close camera

Open LeifSec opened this issue 1 year ago • 5 comments

Describe the bug If creating a camera object, closing it / destroying it (when going out of scope) there is a Cannot allocate memory error after some iterations.

To Reproduce

from picamera2 import Picamera2
from libcamera import ColorSpace, Transform


camera = Picamera2()
configuration = {
    'use_case': 'preview',
    'transform': Transform(),
    'colour_space': ColorSpace.Sycc(),
    'buffer_count': 4,
    'queue': True,
    'main': {'format': 'XBGR8888', 'size': (640, 480)},
    'lores': None, 'raw': {'format': 'SRGGB12_CSI2P', 'size': (640, 480)},
    'controls': {'NoiseReductionMode': 3,
                 'FrameDurationLimits': (100, 83333),
                 'Saturation': 0,
                 'Sharpness': 30,
                 'Brightness': 45, 'AnalogueGain': 5,
                 'ColourGains': (0, 0)},
    'sensor': {},
    'display': 'main',
    'encode': 'main'}

for i in range(0, 20):
    camera.configure(configuration)

camera.close()



for i in range(0, 20):
    print("\n\n -------------------------------", i)
    camera = Picamera2()
    camera.configure(configuration)   # error here after 7 iterations
    camera.close()

Console Output, Screenshots

 ------------------------------- 7
[6:41:18.507074914] [32605]  INFO Camera camera.cpp:1183 configuring streams: (0) 640x480-XBGR8888 (1) 2028x1520-SBGGR12_CSI2P
[6:41:18.508306508] [32611]  INFO RPI vc4.cpp:608 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 2028x1520-SBGGR12_1X12 - Selected unicam format: 2028x1520-pBCC
Traceback (most recent call last):
  File "/home/pi/./memory.py", line 37, in <module>
    camera.configure(configuration)
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 1104, in configure
    self.configure_(camera_config)
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 1087, in configure_
    self.allocator.allocate(libcamera_config)
  File "/usr/lib/python3/dist-packages/picamera2/allocators/dmaallocator.py", line 43, in allocate
    fd = self.dmaHeap.alloc(f"picamera2-{i}", stream_config.frame_size)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/picamera2/dma_heap.py", line 98, in alloc
    ret = fcntl.ioctl(self.__dmaHeapHandle.get(), DMA_HEAP_IOCTL_ALLOC, alloc)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 12] Cannot allocate memory

Hardware :

  • imx477
  • Raspberry Pi 2 Model B Rev 1.1

Additional context Raspberian 12

rpicam-apps build: f74361ee6a56 23-11-2023 (17:01:12)
libcamera build: v0.1.0+118-563cd78e

LeifSec avatar Dec 06 '23 12:12 LeifSec