raspberrypi / libcamera

Other
240 stars 102 forks source link

bug: Segmentation fault error while running. #208

Open kiki-kanri opened 1 day ago

kiki-kanri commented 1 day ago

I'm compiling libcamera and rpicam-apps on a Raspberry Pi 5, but when I run it I encounter Segmentation fault error.

Build with the latest main commit.

Kernel version used: 6.6.47+rpt-rpi-2712

Installed kernels:

linux-headers-6.6.47+rpt-rpi-2712/stable,now 1:6.6.47-1+rpt1 arm64 [installed]
linux-headers-6.6.51+rpt-rpi-2712/stable,now 1:6.6.51-1+rpt3 arm64 [installed,automatic]
linux-headers-rpi-2712/stable,now 1:6.6.51-1+rpt3 arm64 [installed]
linux-image-6.6.47+rpt-rpi-2712-dbg/stable,now 1:6.6.47-1+rpt1 arm64 [installed]
linux-image-6.6.47+rpt-rpi-2712/stable,now 1:6.6.47-1+rpt1 arm64 [installed]
linux-image-6.6.51+rpt-rpi-2712/stable,now 1:6.6.51-1+rpt3 arm64 [installed,automatic]
linux-image-rpi-2712/now 1:6.6.47-1+rpt1 arm64 [installed,upgradable to: 1:6.6.51-1+rpt3]

Error content:

Starting program: /usr/local/bin/rpicam-hello -n
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
[1:06:50.672275772] [77749]  INFO Camera camera_manager.cpp:325 libcamera v0.3.2+98-75fe515a
[New Thread 0x7ffff42eeec0 (LWP 77750)]
[1:06:50.679995789] [77750]  INFO RPI pisp.cpp:695 libpisp version v1.0.7 28196ed6edcf 14-11-2024 (15:48:37)
[New Thread 0x7ffff3a1eec0 (LWP 77751)]
[New Thread 0x7ffff320eec0 (LWP 77752)]
[1:06:50.844189063] [77750]  INFO RPI pisp.cpp:1154 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a to CFE device /dev/media3 and ISP device /dev/media0 using PiSP variant BCM2712_D0
Mode selection for 2304:1296:12:P
    SRGGB10_CSI2P,1536x864/0 - Score: 3400
    SRGGB10_CSI2P,2304x1296/0 - Score: 1000
    SRGGB10_CSI2P,4608x2592/0 - Score: 1900
Stream configuration adjusted
[1:06:50.845701637] [77749]  INFO Camera camera.cpp:1197 configuring streams: (0) 2304x1296-YUV420 (1) 2304x1296-BGGR_PISP_COMP1
[1:06:50.845854063] [77750]  INFO RPI pisp.cpp:1450 Sensor: /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a - Selected sensor format: 2304x1296-SBGGR10_1X10 - Selected CFE format: 2304x1296-PC1B
[New Thread 0x7ffff0d6eec0 (LWP 77753)]
[New Thread 0x7fffebffeec0 (LWP 77754)]
[New Thread 0x7fffeac82ec0 (LWP 77755)]

Thread 3 "rpicam-hello" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff3a1eec0 (LWP 77751)]
libcamera::ipa::Pwl::eval (this=0x7fffec02d0d8, x=4500, span=0x0, updateSpan=<optimized out>) at ../src/ipa/libipa/pwl.cpp:210
210            (x - points_[index].x()) * (points_[index + 1].y() - points_[index].y()) /
(gdb) nt
Undefined command: "nt".  Try "help".
(gdb) bt
#0  libcamera::ipa::Pwl::eval (this=0x7fffec02d0d8, x=4500, span=0x0, updateSpan=<optimized out>) at ../src/ipa/libipa/pwl.cpp:210
#1  0x00007ffff3a86320 in RPiController::Awb::prepareStats (this=this@entry=0x7fffec02d0b0) at ../src/ipa/rpi/controller/rpi/awb.cpp:462
#2  0x00007ffff3a87324 in RPiController::Awb::doAwb (this=this@entry=0x7fffec02d0b0) at ../src/ipa/rpi/controller/rpi/awb.cpp:753
#3  0x00007ffff3a875f8 in RPiController::Awb::asyncFunc (this=0x7fffec02d0b0) at ../src/ipa/rpi/controller/rpi/awb.cpp:410
#4  0x00007ffff7d7e9dc in ?? () from /lib/aarch64-linux-gnu/libstdc++.so.6
#5  0x00007ffff7b2ee90 in start_thread (arg=0x7ffff42ecb17) at ./nptl/pthread_create.c:442
#6  0x00007ffff7b97b1c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:79
Starting program: /usr/local/bin/rpicam-hello -n
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
[0:04:13.460394645] [1031]  INFO Camera camera_manager.cpp:325 libcamera v0.3.2+98-75fe515a
[New Thread 0x7ffff384eec0 (LWP 1033)]
[0:04:13.471504541] [1033]  INFO RPI pisp.cpp:695 libpisp version v1.0.7 28196ed6edcf 14-11-2024 (16:10:56)
[New Thread 0x7ffff2d7eec0 (LWP 1034)]
[New Thread 0x7ffff256eec0 (LWP 1035)]
[0:04:13.777185659] [1033]  INFO RPI pisp.cpp:1154 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a to CFE device /dev/media3 and ISP device /dev/media0 using PiSP variant BCM2712_D0
Mode selection for 2304:1296:12:P
    SRGGB10_CSI2P,1536x864/0 - Score: 3400
    SRGGB10_CSI2P,2304x1296/0 - Score: 1000
    SRGGB10_CSI2P,4608x2592/0 - Score: 1900
Stream configuration adjusted
[0:04:13.780807965] [1031]  INFO Camera camera.cpp:1197 configuring streams: (0) 2304x1296-YUV420 (1) 2304x1296-BGGR_PISP_COMP1
[0:04:13.781349802] [1033]  INFO RPI pisp.cpp:1450 Sensor: /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a - Selected sensor format: 2304x1296-SBGGR10_1X10 - Selected CFE format: 2304x1296-PC1B
[New Thread 0x7fffebffeec0 (LWP 1036)]
[New Thread 0x7fffeb7eeec0 (LWP 1037)]
[New Thread 0x7fffea196ec0 (LWP 1038)]

Thread 3 "rpicam-hello" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff2d7eec0 (LWP 1034)]
libcamera::ipa::Vector<double, 2u, (void*)0>::y<false, void> (this=0x0) at ../src/ipa/libipa/vector.h:69
69  ../src/ipa/libipa/vector.h: No such file or directory.
(gdb) bt
#0  libcamera::ipa::Vector<double, 2u, (void*)0>::y<false, void> (this=0x0) at ../src/ipa/libipa/vector.h:69
#1  0x00007ffff2fadda8 in libcamera::ipa::Pwl::eval (this=0x7fffec02d1f8, x=4500, span=0x0, updateSpan=true) at ../src/ipa/libipa/pwl.cpp:209
#2  0x00007ffff2f8e67c in RPiController::Awb::prepareStats (this=0x7fffec02d1d0) at ../src/ipa/rpi/controller/rpi/awb.cpp:462
#3  0x00007ffff2f9028c in RPiController::Awb::doAwb (this=0x7fffec02d1d0) at ../src/ipa/rpi/controller/rpi/awb.cpp:753
#4  0x00007ffff2f8e2d0 in RPiController::Awb::asyncFunc (this=0x7fffec02d1d0) at ../src/ipa/rpi/controller/rpi/awb.cpp:410
#5  0x00007ffff2f983f4 in std::__invoke_impl<void, void (RPiController::Awb::*&)(), RPiController::Awb*&> (
    __f=@0x7fffec19b638: (void (RPiController::Awb::*)(RPiController::Awb * const)) 0x7ffff2f8e260 <RPiController::Awb::asyncFunc()>,
    __t=@0x7fffec19b648: 0x7fffec02d1d0) at /usr/include/c++/12/bits/invoke.h:74
#6  0x00007ffff2f98328 in std::__invoke<void (RPiController::Awb::*&)(), RPiController::Awb*&> (
    __fn=@0x7fffec19b638: (void (RPiController::Awb::*)(RPiController::Awb * const)) 0x7ffff2f8e260 <RPiController::Awb::asyncFunc()>)
    at /usr/include/c++/12/bits/invoke.h:96
#7  0x00007ffff2f982a0 in std::_Bind<void (RPiController::Awb::*(RPiController::Awb*))()>::__call<void, , 0ul>(std::tuple<>&&, std::_Index_tuple<0ul>) (
    this=0x7fffec19b638, __args=...) at /usr/include/c++/12/functional:484
#8  0x00007ffff2f98238 in std::_Bind<void (RPiController::Awb::*(RPiController::Awb*))()>::operator()<, void>() (this=0x7fffec19b638)
    at /usr/include/c++/12/functional:567
#9  0x00007ffff2f981e8 in std::__invoke_impl<void, std::_Bind<void (RPiController::Awb::*(RPiController::Awb*))()>>(std::__invoke_other, std::_Bind<void (RPiController::Awb::*(RPiController::Awb*))()>&&) (__f=...) at /usr/include/c++/12/bits/invoke.h:61
#10 0x00007ffff2f981a0 in std::__invoke<std::_Bind<void (RPiController::Awb::*(RPiController::Awb*))()>>(std::_Bind<void (RPiController::Awb::*(RPiController::Awb*))()>&&) (__fn=...) at /usr/include/c++/12/bits/invoke.h:96
#11 0x00007ffff2f9813c in std::thread::_Invoker<std::tuple<std::_Bind<void (RPiController::Awb::*(RPiController::Awb*))()> > >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (this=0x7fffec19b638) at /usr/include/c++/12/bits/std_thread.h:252
#12 0x00007ffff2f98110 in std::thread::_Invoker<std::tuple<std::_Bind<void (RPiController::Awb::*(RPiController::Awb*))()> > >::operator()() (
    this=0x7fffec19b638) at /usr/include/c++/12/bits/std_thread.h:259
#13 0x00007ffff2f980f0 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<std::_Bind<void (RPiController::Awb::*(RPiController::Awb*))()> > > >::_M_run() (this=0x7fffec19b630) at /usr/include/c++/12/bits/std_thread.h:210
#14 0x00007ffff7bae9dc in ?? () from /lib/aarch64-linux-gnu/libstdc++.so.6
#15 0x00007ffff795ee90 in start_thread (arg=0x7ffff384b1f7) at ./nptl/pthread_create.c:442
#16 0x00007ffff79c7b1c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:79
kiki-kanri commented 1 day ago

Using tag v0.3.2+rpt20240927 build works fine!

gasparramoa commented 22 hours ago

Hi everyone,

I also had a Segmentation fault when trying to use libcamera with tuning file options: rpicam-still -o test.png --tuning-file /home/tactonom/tuning-files/imx219_70d.json

Error:

$ rpicam-still -o test.png --tuning-file /home/tactonom/tuning-files/imx219_70d.json
[0:08:49.763123151] [1122]  INFO Camera camera_manager.cpp:325 libcamera v0.3.2+98-75fe515a
[0:08:49.801658431] [1126]  WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
[0:08:49.804591582] [1126]  WARN RPI vc4.cpp:393 Mismatch between Unicam and CamHelper for embedded data usage!
[0:08:49.805831088] [1126]  INFO RPI vc4.cpp:447 Registered camera /base/soc/i2c0mux/i2c@1/imx219@10 to Unicam device /dev/media4 and ISP device /dev/media2
[0:08:49.806039586] [1126]  INFO RPI pipeline_base.cpp:1120 Using configuration file '/usr/local/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
Preview window unavailable
Mode selection for 1640:1232:12:P
    SRGGB10_CSI2P,640x480/0 - Score: 4504.81
    SRGGB10_CSI2P,1640x1232/0 - Score: 1000
    SRGGB10_CSI2P,1920x1080/0 - Score: 1541.48
    SRGGB10_CSI2P,3280x2464/0 - Score: 1718
    SRGGB8,640x480/0 - Score: 5504.81
    SRGGB8,1640x1232/0 - Score: 2000
    SRGGB8,1920x1080/0 - Score: 2541.48
    SRGGB8,3280x2464/0 - Score: 2718
[0:08:49.815790426] [1122]  INFO Camera camera.cpp:1197 configuring streams: (0) 1640x1232-YUV420 (1) 1640x1232-SBGGR10_CSI2P
[0:08:49.816456397] [1126]  INFO RPI vc4.cpp:622 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 1640x1232-SBGGR10_1X10 - Selected unicam format: 1640x1232-pBAA
Segmentation fault

Libcamera version:

rpicam-apps build: v1.5.3 50958df98d3c 13-11-2024 (16:55:55)
rpicam-apps capabilites: egl:1 qt:1 drm:1 libav:1
libcamera build: v0.3.2+98-75fe515a

However, as @kiki-kanri, by changing to version tag v0.3.2+rpt20240927 I have no errors when I do: rpicam-still -o test.png --tuning-file /home/tactonom/tuning-files/imx219_70d.json

rpicam-apps build: v1.5.3 50958df98d3c 14-11-2024 (17:45:16)
rpicam-apps capabilites: egl:1 qt:1 drm:1 libav:1
libcamera build: v0.3.2+27-7330f29b
naushir commented 22 hours ago

I've not been able to reproduce this in my brief testing. I'll try again tomorrow and report back.

naushir commented 7 hours ago

@kiki-kanri are you using a custom/modified json tuning file? I still cannot seem to reproduce this bug.

kiki-kanri commented 7 hours ago

@kiki-kanri are you using a custom/modified json tuning file? I still cannot seem to reproduce this bug.

I don't use json tuning files, but I do set up the compilation and linking parameters, I'll test it on a clean system sometime.

Just simply run rpicam-hello -n.

Here's the program in order and compiled by me:

naushir commented 7 hours ago

What compiler have you setup?

kiki-kanri commented 6 hours ago

What compiler have you setup?

Here's the compilation and linking parameters that work for me on v0.3.2+rpt20240927.

cflags:

-fipa-pta
-floop-block
-floop-interchange
-floop-strip-mine
-flto=4
-fomit-frame-pointer
-funroll-loops
-I/opt/openssl3/include
-march=armv8.2-a
-mtune=cortex-a76
-O3
-pthread

ldflags: -L/opt/openssl3/lib

build libcamera command:

CFLAGS="$BASE_CFLAGS" CPPFLAGS="$BASE_CFLAGS -Wno-unused-parameter" CXXFLAGS="$BASE_CFLAGS" LD_LIBRARY_PATH="/opt/openssl3/lib:$LD_LIBRARY_PATH" meson setup ./build \
        --backend=ninja \
        --buildtype=release \
        -Db_lto=true \
        -Db_ndebug=true \
        -Db_pch=true \
        -Dcam=disabled \
        -Ddocumentation=disabled \
        -Dgstreamer=disabled \
        -Dipas=rpi/pisp,rpi/vc4 \
        -Dlc-compliance=disabled \
        -Dpipelines=rpi/pisp,rpi/vc4 \
        -Dpycamera=disabled \
        -Dqcam=disabled \
        -Dstrip=true \
        -Dtest=false \
        -Dtracing=disabled \
        -Dv4l2=true

Since there are so many variables, I need to find the time to test again on a clean system if the then current parameters are usable in the new version.