Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mac build, OpenCV4 compatibility, fix use-after-free causing memory corruption #177

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ add_library(dso ${dso_SOURCE_FILES} ${dso_opencv_SOURCE_FILES} ${dso_pangolin_SO
#set_property( TARGET dso APPEND_STRING PROPERTY COMPILE_FLAGS -Wall )


if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # OSX
set(BOOST_THREAD_LIBRARY boost_thread-mt)
else()
set(BOOST_THREAD_LIBRARY boost_thread)
endif()
#if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # OSX
# set(BOOST_THREAD_LIBRARY boost_thread-mt)
#else()
# set(BOOST_THREAD_LIBRARY boost_thread)
#endif()

# build main executable (only if we have both OpenCV and Pangolin)
if (OpenCV_FOUND AND Pangolin_FOUND)
message("--- compiling dso_dataset.")
add_executable(dso_dataset ${PROJECT_SOURCE_DIR}/src/main_dso_pangolin.cpp )
target_link_libraries(dso_dataset dso boost_system cxsparse ${BOOST_THREAD_LIBRARY} ${LIBZIP_LIBRARY} ${Pangolin_LIBRARIES} ${OpenCV_LIBS})
target_link_libraries(dso_dataset dso ${Boost_LIBRARIES} ${CSPARSE_LIBRARY} ${BOOST_THREAD_LIBRARY} ${LIBZIP_LIBRARY} ${Pangolin_LIBRARIES} ${OpenCV_LIBS})
else()
message("--- not building dso_dataset, since either don't have openCV or Pangolin.")
endif()
Expand Down
10 changes: 5 additions & 5 deletions src/FullSystem/FullSystemMarginalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ void FullSystem::marginalizeFrame(FrameHessian* frame)
if(r->target == frame)
{
if(ph->lastResiduals[0].first == r)
ph->lastResiduals[0].first=0;
ph->lastResiduals[0].first=nullptr;
else if(ph->lastResiduals[1].first == r)
ph->lastResiduals[1].first=0;
ph->lastResiduals[1].first=nullptr;


if(r->host->frameID < r->target->frameID)
Expand All @@ -190,7 +190,9 @@ void FullSystem::marginalizeFrame(FrameHessian* frame)
}
}


// efFrame is only unused once we finish droppping residuals
delete frame->efFrame;
frame->efFrame = nullptr;

{
std::vector<FrameHessian*> v;
Expand All @@ -208,8 +210,6 @@ void FullSystem::marginalizeFrame(FrameHessian* frame)
frameHessians[i]->idx = i;




setPrecalcValues();
ef->setAdjointsF(&Hcalib);
}
Expand Down
8 changes: 4 additions & 4 deletions src/IOWrapper/OpenCV/ImageRW_OpenCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace IOWrap
{
MinimalImageB* readImageBW_8U(std::string filename)
{
cv::Mat m = cv::imread(filename, CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat m = cv::imread(filename, cv::ImreadModes::IMREAD_GRAYSCALE);
if(m.rows*m.cols==0)
{
printf("cv::imread could not read image %s! this may segfault. \n", filename.c_str());
Expand All @@ -52,7 +52,7 @@ MinimalImageB* readImageBW_8U(std::string filename)

MinimalImageB3* readImageRGB_8U(std::string filename)
{
cv::Mat m = cv::imread(filename, CV_LOAD_IMAGE_COLOR);
cv::Mat m = cv::imread(filename, cv::ImreadModes::IMREAD_COLOR);
if(m.rows*m.cols==0)
{
printf("cv::imread could not read image %s! this may segfault. \n", filename.c_str());
Expand All @@ -70,7 +70,7 @@ MinimalImageB3* readImageRGB_8U(std::string filename)

MinimalImage<unsigned short>* readImageBW_16U(std::string filename)
{
cv::Mat m = cv::imread(filename, CV_LOAD_IMAGE_UNCHANGED);
cv::Mat m = cv::imread(filename, cv::ImreadModes::IMREAD_UNCHANGED);
if(m.rows*m.cols==0)
{
printf("cv::imread could not read image %s! this may segfault. \n", filename.c_str());
Expand All @@ -88,7 +88,7 @@ MinimalImage<unsigned short>* readImageBW_16U(std::string filename)

MinimalImageB* readStreamBW_8U(char* data, int numBytes)
{
cv::Mat m = cv::imdecode(cv::Mat(numBytes,1,CV_8U, data), CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat m = cv::imdecode(cv::Mat(numBytes,1,CV_8U, data), cv::ImreadModes::IMREAD_GRAYSCALE);
if(m.rows*m.cols==0)
{
printf("cv::imdecode could not read stream (%d bytes)! this may segfault. \n", numBytes);
Expand Down
10 changes: 4 additions & 6 deletions src/OptimizationBackend/EnergyFunctional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void EnergyFunctional::accumulateSCF_MT(MatXX &H, VecX &b, bool MT)
}
}

void EnergyFunctional::resubstituteF_MT(VecX x, CalibHessian* HCalib, bool MT)
void EnergyFunctional::resubstituteF_MT(const VecX &x, CalibHessian* HCalib, bool MT)
{
assert(x.size() == CPARS+nFrames*8);

Expand Down Expand Up @@ -419,7 +419,6 @@ EFResidual* EnergyFunctional::insertResidual(PointFrameResidual* r)
EFResidual* efr = new EFResidual(r, r->point->efPoint, r->host->efFrame, r->target->efFrame);
efr->idxInAll = r->point->efPoint->residualsAll.size();
r->point->efPoint->residualsAll.push_back(efr);

connectivityMap[(((uint64_t)efr->host->frameID) << 32) + ((uint64_t)efr->target->frameID)][0]++;

nResiduals++;
Expand Down Expand Up @@ -489,7 +488,6 @@ void EnergyFunctional::dropResidual(EFResidual* r)
else
r->host->data->shell->statistics_outlierResOnThis++;


connectivityMap[(((uint64_t)r->host->frameID) << 32) + ((uint64_t)r->target->frameID)][0]--;
nResiduals--;
r->data->efResidual=0;
Expand Down Expand Up @@ -583,7 +581,7 @@ void EnergyFunctional::marginalizeFrame(EFFrame* fh)
}
frames.pop_back();
nFrames--;
fh->data->efFrame=0;
fh->data->efFrame=nullptr;

assert((int)frames.size()*8+CPARS == (int)HM.rows());
assert((int)frames.size()*8+CPARS == (int)HM.cols());
Expand All @@ -606,7 +604,6 @@ void EnergyFunctional::marginalizeFrame(EFFrame* fh)
EFDeltaValid=false;

makeIDX();
delete fh;
}


Expand All @@ -629,8 +626,9 @@ void EnergyFunctional::marginalizePointsF()
{
p->priorF *= setting_idepthFixPriorMargFac;
for(EFResidual* r : p->residualsAll)
if(r->isActive())
if(r->isActive()) {
connectivityMap[(((uint64_t)r->host->frameID) << 32) + ((uint64_t)r->target->frameID)][1]++;
}
allPointsToMarg.push_back(p);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/OptimizationBackend/EnergyFunctional.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class EnergyFunctional {

VecX getStitchedDeltaF() const;

void resubstituteF_MT(VecX x, CalibHessian* HCalib, bool MT);
void resubstituteF_MT(const VecX &x, CalibHessian* HCalib, bool MT);
void resubstituteFPt(const VecCf &xc, Mat18f* xAd, int min, int max, Vec10* stats, int tid);

void accumulateAF_MT(MatXX &H, VecX &b, bool MT);
Expand Down