mv3d: fix a bug using nullptr
authorTae-Young Chung <ty83.chung@samsung.com>
Thu, 22 Sep 2022 04:21:45 +0000 (13:21 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Thu, 22 Sep 2022 06:06:57 +0000 (15:06 +0900)
[Issue type] : bug fix (SVACE: WGID 499264)

mDepthCallback uses deallocated memory of the variable 'base'.
It should be mv_source_h of a left image.
With dfs-adaptation change,
```
commit 1607630a5887d961cd71d0e9663e9945d70fc3ae
Author: Tae-Young Chung <ty83.chung@samsung.com>
Date:   Thu Sep 22 13:19:04 2022 +0900

    Add getLeftData() and getRigthData()

    [Version] 1.0.9-0
    [Issue type] update
```
getLeftData() returns the pointer of a left image
and the returned pointer is used to fill mv_source_h.

Change-Id: I89af7686e485a102bc444720583bf26739e08809

mv_3d/3d/include/Mv3d.h
mv_3d/3d/src/Mv3d.cpp

index df04d92f1ae3e23e0e84904fa10666028a39f8c4..8f3558c54dfdec2e7aac89826fe1cafbc1fc53ac 100644 (file)
@@ -65,6 +65,8 @@ namespace mv3d
 
                GAsyncQueue *mDfsAsyncQueue;
 
+               mv_source_h mInternalSource;
+
                void GetBufferFromSource(mv_source_h source,
                                                                unsigned char*& buffer,
                                                                unsigned int& width,
index 521c947d6983835995213e662f5bf872d19a1618..dc4c05c47c39010d48651276b4fdafbd27f4fb0d 100644 (file)
@@ -50,7 +50,8 @@ namespace mv3d
                mDepthCallback(nullptr),
                mPointcloudCallback(nullptr),
                mDfsIsLive(false),
-               mDfsAsyncQueue(nullptr)
+               mDfsAsyncQueue(nullptr),
+               mInternalSource(nullptr)
        {
                LOGI("ENTER");
 #ifdef MV_3D_POINTCLOUD_IS_AVAILABLE
@@ -77,6 +78,11 @@ namespace mv3d
                        delete mDfsAdaptor;
                }
 
+               if (mInternalSource) {
+                       mv_destroy_source(mInternalSource);
+                       mInternalSource = nullptr;
+               }
+
                LOGI("LEAVE");
        }
 
@@ -303,6 +309,14 @@ namespace mv3d
                                mDfsAsyncQueue = nullptr;
                        }
 
+                       if (mInternalSource) {
+                               int ret = mv_destroy_source(mInternalSource);
+                               if (ret != MEDIA_VISION_ERROR_NONE) {
+                                       LOGE("Fail to destroy intern source. But keep going..");
+                               }
+                               mInternalSource = nullptr;
+                       }
+
                        GetDfsDataFromSources(baseSource, extraSource, input);
 
                        mDfsAdaptor->run(input);
@@ -362,6 +376,13 @@ namespace mv3d
 
                        std::shared_ptr<DfsInputData> input(new DfsInputData);
                        GetDfsDataFromSources(baseSource, extraSource, *input);
+                       if (!mInternalSource) {
+                               int ret = mv_create_source(&mInternalSource);
+                               if (ret != MEDIA_VISION_ERROR_NONE) {
+                                       LOGE("Fail to create internal source");
+                                       return MEDIA_VISION_ERROR_INTERNAL;
+                               }
+                       }
                        g_async_queue_push(mDfsAsyncQueue, static_cast<void*>(
                                                                                        new std::shared_ptr<DfsInputData>(
                                                                                                std::move(input))));
@@ -388,8 +409,16 @@ namespace mv3d
                        handle->mDfsAdaptor->run(*input);
 
                        auto depthData = handle->mDfsAdaptor->getOutputData();
+                       auto leftData = handle->mDfsAdaptor->getLeftData();
+                       mv_source_fill_by_buffer(handle->mInternalSource,
+                                                               static_cast<unsigned char*>(leftData.data),
+                                                               leftData.width,
+                                                               leftData.height,
+                                                               leftData.stride * leftData.height,
+                                                               leftData.type == DFS_DATA_TYPE_UINT8C3 ? MEDIA_VISION_COLORSPACE_RGB888 :
+                                                                                               MEDIA_VISION_COLORSPACE_Y800);
                        handle->mDepthCallback(
-                                       static_cast<mv_source_h>(base),
+                                       static_cast<mv_source_h>(handle->mInternalSource),
                                        static_cast<DepthTypePtr>(depthData.data),
                                        depthData.width, depthData.height,
                                        handle->mDepthUserData);
@@ -402,7 +431,7 @@ namespace mv3d
                                handle->GetPointcloudFromSource(*input, depthData, p);
 
                                mv_3d_pointcloud_h pcd = &p;
-                               handle->mPointcloudCallback(static_cast<mv_source_h>(base),
+                               handle->mPointcloudCallback(static_cast<mv_source_h>(mInternalSource),
                                                pcd,
                                                handle->mPointcloudUserData);
                                auto pPcd = static_cast<std::shared_ptr<open3d::geometry::PointCloud>*>(p.pointcloud);
@@ -412,6 +441,7 @@ namespace mv3d
 #endif
                        delete [] static_cast<unsigned char*>(input->data);
                        delete [] static_cast<unsigned char*>(input->extraData);
+                       mv_source_clear(handle->mInternalSource);
                        input.reset();
                }