Libnvds_nvdcf segfaulting

Hey!

I am trying to use the low level library for the tracker alongside the nvdcf. I’m having trouble using the libnvds_nvdcf.

So far this is what I have come up with:

auto configFile = std::string("/opt/nvidia/deepstream/deepstream-4.0/sources/apps/sample_apps/deepstream-test2/dstest2_tracker_config.txt");
auto configFileRecasted = const_cast < char * > (configFile.c_str());

// One obvious error is that `pitch` values should be in bytes, whereas `width` values are in pixels

NvMOTQuery query;
NvMOT_Query(configFile.size(), configFileRecasted, & query);

NvMOTPerTransformBatchConfig transformBatchConfig;
transformBatchConfig.bufferType = query.memType;
transformBatchConfig.colorFormat = query.colorFormats[0];
transformBatchConfig.maxWidth = 640;
transformBatchConfig.maxHeight = 368;
transformBatchConfig.maxPitch = 1;
transformBatchConfig.maxSize = 640 * 368 * 1;

//            uint8_t numTransforms: The number of color formats required by the lowlevel library. The valid range for this field is 0 to NVMOT_MAX_TRANSFORMS. Set
//            this to 0 if the library does not require any visual data. Note that 0 does not mean
//            that untransformed data will be passed to the library
NvMOTConfig config;
config.computeConfig = query.computeConfig;
config.maxStreams = 1;
config.customConfigFilePath = configFileRecasted;
config.customConfigFilePathSize = configFile.size();
config.perTransformBatchConfig = & transformBatchConfig;
config.numTransforms = query.numTransforms;

NvMOTContextHandle contextHandle;
NvMOTConfigResponse configResponse;

auto status_init = NvMOT_Init( & config, & contextHandle, & configResponse);
if (status_init == NvMOTStatus_OK) {
    std::cout << "STATUS INIT OK" << std::endl;
}

The proble is that when I hit NvMOT_Query, I get a segmentation fault:

/opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so(NvMOT_Query+0x5)[0x7f49dc611625]

If I ignore calling the Query, I hit a segmentation fault on: NvMOT_Init()

/opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so(_ZN12NvMOTContextD1Ev+0x4)[0x7fcb3cdc19d4]
/opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so(NvMOT_DeInit+0xe)[0x7fcb3cdc364e]
/opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so(NvMOT_Init+0x20)[0x7fcb3cdc3690]
/home/user/gazebo_dev/vino-server/bin/runtime/libmodule_nvidia_tracker.so(_ZN12ThirdInsight7Modules19ModuleNvidiaTracker6doInitEv+0xfb)[0x7fcb3d303349]
/home/user/gazebo_dev/vino-server/bin/x86_64/debug/library_module_debug/liblibrary_module_debug.so(_ZN12ThirdInsight7Library6Module10ModuleBase4initEv+0x144)[0x7fcb3f08b826]

This only happens when I use the library libnvds_nvdcf.

Have you checked https://devtalk.nvidia.com/default/topic/1066252/deepstream-sdk/klt-nvmot-usage/ and https://docs.nvidia.com/metropolis/deepstream/plugin-manual/index.html#page/DeepStream_Plugin_Manual%2Fdeepstream_plugin_details.02.02.html%23wwpID0E0VV0HA

BTW, could you check the core dump file using gdb to check more debug info?

Hey bcao! This is my stacktrace. It does not seem to be outputting much. I am able to get the libnvds_mot_klt to work but not the libnvds_nvdcf.

My CMAKE flags: “-m64 -g -O0 -rdynamic”

Thread 13 "module_server" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffae2c0700 (LWP 1829)]
__GI___libc_free (mem=0x894855c3c9ffffff) at malloc.c:3103
3103	malloc.c: No such file or directory.
(gdb) backtrace
#0  0x00007ffff68c298d in __GI___libc_free (mem=0x894855c3c9ffffff) at malloc.c:3103
#1  0x00007ffff043b9dd in NvMOTContext::~NvMOTContext() () at /opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so
#2  0x00007ffff043d64e in NvMOT_DeInit () at /opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so
#3  0x00007ffff043d690 in NvMOT_Init () at /opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so
#4  0x00007ffff59c1dc3 in ThirdInsight::Modules::ModuleNvidiaTracker::doInit() (this=0x5555559901b0)
    at /home/user/gazebo_dev/vino-server/src/modules/module_nvidia_tracker/moduleNvidiaTracker.cxx:83
#5  0x00007ffff774e826 in ThirdInsight::Library::Module::ModuleBase::init() (this=0x5555559901b0)
    at /home/user/gazebo_dev/vino-server/src/lib/library_module/modules/moduleBase.cxx:158
#6  0x00007ffff77463cf in ThirdInsight::Library::Module::GroupManager::doGroupLoop() (this=0x555555851e10)
    at /home/user/gazebo_dev/vino-server/src/lib/library_module/modules/groupManager.cxx:179
#7  0x00007ffff77462e5 in ThirdInsight::Library::Module::GroupManager::doGroupLoop() (this=0x555555850f90)
    at /home/user/gazebo_dev/vino-server/src/lib/library_module/modules/groupManager.cxx:155
#8  0x00007ffff774682e in ThirdInsight::Library::Module::GroupManager::groupLoop() (this=0x555555850f90)
    at /home/user/gazebo_dev/vino-server/src/lib/library_module/modules/groupManager.cxx:264

Using thread apply all bt full

#0  0x00007ffff68c298d in __GI___libc_free (mem=0x894855c3c9ffffff) at malloc.c:3103
        ar_ptr = <optimized out>
        p = <optimized out>
        hook = 0x0
        mem = 0x894855c3c9ffffff
        hook = 0x0
#1  0x00007ffff043b9dd in NvMOTContext::~NvMOTContext() () at /opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so
#2  0x00007ffff043d64e in NvMOT_DeInit () at /opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so
#3  0x00007ffff043d690 in NvMOT_Init () at /opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so
#4  0x00007ffff59c1dc3 in ThirdInsight::Modules::ModuleNvidiaTracker::doInit() (this=0x5555559901b0)
    at /home/user/gazebo_dev/vino-server/src/modules/module_nvidia_tracker/moduleNvidiaTracker.cxx:83
        configFile = "/opt/nvidia/deepstream/deepstream-4.0/sources/apps/sample_apps/deepstream-test2/dstest2_tracker_config.txt"
        configFileRecasted = 0x7fffa8000ca0 "/opt/nvidia/deepstream/deepstream-4.0/sources/apps/sample_apps/deepstream-test2/dstest2_tracker_config.txt"
        query = 
          {computeConfig = 1 '\001', numTransforms = 1 '\001', colorFormats = {NVBUF_COLOR_FORMAT_NV12, 2535390720, 171161968, 2922117408}, memType = NVBUF_MEM_CUDA_UNIFIED, supportBatchProcessing = true}
        transformBatchConfig = {bufferType = NVBUF_MEM_CUDA_UNIFIED, maxWidth = 640, maxHeight = 368, maxPitch = 1, maxSize = 235520, colorFormat = 6}
        config = 
          {computeConfig = 1 '\001', maxStreams = 1, numTransforms = 1 '\001', perTransformBatchConfig = 0x7fffae2bf7d0, miscConfig = {gpuId = 4151457464, maxObjPerStream = 32767, maxObjPerBatch = 0}, customConfigFilePathSize = 106, customConfigFilePath = 0x7fffa8000ca0 "/opt/nvidia/deepstream/deepstream-4.0/sources/apps/sample_apps/deepstream-test2/dstest2_tracker_config.txt"}
        contextHandle = 0x5555555dd620 <__gnu_cxx::__exchange_and_add_dispatch(_Atomic_word*, int)+46>
        configResponse = {summaryStatus = 2922117120, computeStatus = 32767, transformBatchStatus = 2922117176, miscConfigStatus = 32767, customConfigStatus = 2922117088}
        status_init = (NvMOTStatus_Error | NvMOTStatus_Invalid_Path | unknown: 32764)
        surface = 0xffffffffae2bf790
        surfaceCreateParams = 
          {gpuId = 2818575440, width = 32767, height = 2818575424, size = 32767, isContiguous = 96, colorFormat = 32767, layout = (unknown: 2535390720), memType = 171161968}
        result = -1372850304
        yDevMem = 0x7fffa8000c48
        motFrame = 
            {streamID = 140736115505360, frameNum = 2922117616, timeStamp = 0, timeStampValid = false, doTracking = false, reset = false, numBuffers = 0 '\000', bufferList = 0x7fffae2bf910, objectsIn = {detectionDone = 96, list = 0x7fffae2bf940, numAllocated = 1435351488, numFilled = 21845}}
        processParams = {numFrames = 2922117040, frameList = 0x7fffa8000c40}
---Type <return> to continue, or q <return> to quit---
        trackedObjList = {{streamID = 18446744072336701936, frameNum = 2818575432, valid = 255, list = 0x7fffae2bf960, numAllocated = 1432253587, numFilled = 21845}}
        trackedObjBatch = {list = 0x7fffae2bf7c0, numAllocated = 1432240575, numFilled = 21845}
        frameNum = -1
        videoCapture = 
          {_vptr.VideoCapture = 0x7fffae2bf8a0, cap = {<std::shared_ptr<CvCapture>> = std::shared_ptr<CvCapture> (use count 161, weak count -1) = {get() = 0x7fffae2bf9f0}, <No data fields>}, icap = {<std::shared_ptr<cv::IVideoCapture>> = std::shared_ptr<cv::IVideoCapture> (use count -143517856, weak count 32766) = {get() = 0x5555558db9c0}, <No data fields>}, throwOnFail = false}
#5  0x00007ffff774e826 in ThirdInsight::Library::Module::ModuleBase::init() (this=0x5555559901b0)
    at /home/user/gazebo_dev/vino-server/src/lib/library_module/modules/moduleBase.cxx:158
        __FUNCTION__ = "init"
#6  0x00007ffff77463cf in ThirdInsight::Library::Module::GroupManager::doGroupLoop() (this=0x555555851e10)
    at /home/user/gazebo_dev/vino-server/src/lib/library_module/modules/groupManager.cxx:179
        module = 0x5555559901b0
        lock = {_M_device = 0x555555852000, _M_owns = true}
        it = 0x5555559901b0
        minSleepId = ""
        deletedAModule = false
        allowRunModules = true
        __FUNCTION__ = "doGroupLoop"
#7  0x00007ffff77462e5 in ThirdInsight::Library::Module::GroupManager::doGroupLoop() (this=0x555555850f90)
    at /home/user/gazebo_dev/vino-server/src/lib/library_module/modules/groupManager.cxx:155
        module = 0x555555851e10
        lock = {_M_device = 0x555555851180, _M_owns = true}
        it = 0x555555851e10
        minSleepId = ""
        deletedAModule = false
        allowRunModules = true
        __FUNCTION__ = "doGroupLoop"
#8  0x00007ffff774682e in ThirdInsight::Library::Module::GroupManager::groupLoop() (this=0x555555850f90)
    at /home/user/gazebo_dev/vino-server/src/lib/library_module/modules/groupManager.cxx:264
        sleepTimeNanos = 999935466

Thanks, would you mind to share a sample code and makefile for me to repro your issue, I will debug locally.

Here’s the code in a CMAKE project.

https://drive.google.com/file/d/1weU1UR91d-aqF-2u-S4tztz1z_qOcgO1/view?usp=sharing

Could you give the permission to acess the code or share me with a tar file including the source code and makefile?

Sorry! I made it public for everybody.

Thanks, checking internally and give you response later.

Hey Customer,
Is it required to set “set(CMAKE_CXX_FLAGS “-m64 -g -O0 -rdynamic”)”?
BTW, what is your platform and jetpek version?

I’m using:

Deepstream:     deepstream-4.0_4.0.2-1
TensortRT:      tensorrt-repo-ubuntu1804-cuda10.1-trt6.0.1.5
Driver Version: 430.64
CUDA Version:   10.1
OS:             Ubuntu 18.04
ARCH:           x86_64

I can actually successfully run the gstreamer example /opt/nvidia/deepstream/deepstream-4.0/sources/apps/sample_apps/deepstream-test2/ but I cannot use the low level library by itself successfully with the DCF.

It’s not required that I set those CXX flags. I have tried different configurations but I still get the segmentation fault.

Hey!

Is there any update on this issue?

Thanks

–> Seems NvMOT_Query succesful, your issue is within NvMOT_Init, here is one workable thread, you can refer to this topic, https://devtalk.nvidia.com/default/topic/1066252/deepstream-sdk/klt-nvmot-usage/post/5400741/#5400741

I don’t have a problem with the KLT tracker. That works for me. The DCF is the one segfaulting.

I have this new error that is getting outputted when running the NvMOT_Init()

OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/shaunakg/opencv-3.4.0-static/opencv-3.4.0/modules/core/src/persistence.cpp, line 4484

!![ERROR] /home/shaunakg/opencv-3.4.0-static/opencv-3.4.0/modules/core/src/persistence.cpp:4484: error: (-49) Input file is empty in function cvOpenFileStorage

Any ideas?

Hi Did you modify the code? i can repro your previous issue at comment 3#, but can not for your latest issue;
if code updated, please share so that we can recreate your issue and do a further check.

I don’t think I changed anything. It’s OK. I think the first issue is the one I need help with. Do you have any idea what is happening?

Customer,

Your last error seems related to the low-level tracker config file in .yml. It seems like the path is given, but maybe invalid config format is found. Can you try not using any config file (i.e., “” to the config path) so that the low-level tracker can run with its default setting?

@pshin

I figured it out. There were 2 issues. First is that I forgot to set the NvMOTMiscConfig struct inside the NvMOTConfig. Second, I incorrectly set the path to the customConfigFilePath in the NvMOTConfig config and needed to use the low level tracker config.

Thanks for all your help! I have one more question which is a side-question. Is there code someplace where I can do conversions from RGB -> NV12?

please refer to this topic,
https://devtalk.nvidia.com/default/topic/1073066/jetson-nano/gstreamer-that-returns-an-rgb-stream/post/5436314/#5436314