-
Notifications
You must be signed in to change notification settings - Fork 767
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
Expressions cause segfault on Windows (MSVC 2019 v16) #1336
Comments
Update: I removed
so it's like Record* record = new Record(...); instead of Record* record = new (ptr) Record(...); Now the examples seem to work (no crash, low final error). Can someone smarter than me say if this modification is safe? |
Interesting. This is the placement new operator and I remember it being crucial for performance and correctness. I have no idea why it would give problems on windows, unless there is some change in how they handle this (fairly rarely used) C++ feature. |
@laxnpander Could you try modifying
|
@ProfFan Still segfaulting. I just realised that Edit: Maybe I was mistaken, Pose2SLAMExampleExpressions seems to be crashing as well. Stack trace for this: Pose2SLAMExampleExpressions.exe!gtsam::internal::ExecutionTrace<gtsam::Pose2>::~ExecutionTrace<gtsam::Pose2>() Zeile 174 C++
Pose2SLAMExampleExpressions.exe!gtsam::Expression<gtsam::Pose2>::valueAndJacobianMap(const gtsam::Values & values, gtsam::internal::JacobianMap & jacobians) Zeile 224 C++
Pose2SLAMExampleExpressions.exe!gtsam::ExpressionFactor<gtsam::Pose2>::linearize(const gtsam::Values & x) Zeile 139 C++
gtsamDebug.dll!gtsam::NonlinearFactorGraph::linearize(const gtsam::Values & linearizationPoint) Zeile 270 C++
gtsamDebug.dll!gtsam::GaussNewtonOptimizer::iterate() Zeile 49 C++
gtsamDebug.dll!gtsam::NonlinearOptimizer::defaultOptimize() Zeile 95 C++
gtsamDebug.dll!gtsam::NonlinearOptimizer::optimize() Zeile 98 C++
Pose2SLAMExampleExpressions.exe!main(int argc, char * * argv) Zeile 72 C++ |
@ProfFan: Out of curiosity: Did you try running these examples on a windows system? I tried on two different laptops and both were throwing the same error. Same MSVC version though. The CI also just checks for compilation. I just wonder if this is a common issue or related to my configuration... |
It appears the issue is caused by destruction order. In MSVC, the pointer is being deallocated prior to internal::ExecutionTrace being destroyed.
In the destructor, it is invoking a call on the dangling pointer.
In my workaround, I used std::unique_ptr<> with a custom deleter. After this change, my test succeeded. Note that I seem to encounter the error when running in Debug, Release seems to be happy accessing the dangling pointer.
|
Hi @oicchris, great sleuthing! Would you be willing to do a quick PR with your fix for the _MSC_VER path? |
Pfff please ignore the force pushes.. was attempting to reword a comment to make it palatable. Didn't realize it would retain the extra pushes. I'm new to Github, is there a way to clean up the above mess? |
Fix (issue #1336) dangling pointer access violation.
Closing, thank you @oicchris ! |
Description
Expressions seem to cause a segfault on Windows 2019 v16 (potentially others as well). None of the examples with expressions work. According to the debugger, the following line causes the crash (ExpressionNode.h, L279):
Stacktrace:
Steps to reproduce
CMake configuration is with GTSAM_BUILD_UNSTABLE=OFF and GTSAM_BUILD_PYTHON=OFF. Compiler used is MSVC2019 v16 with Boost 1.72 and GTSAM version of Eigen3.
Expected behavior
It should not segfault.
Environment
MSVC2019 v16, CMake 3.23, Boost 1.72, no TBB, Eigen3 shipped with GTSAM
Additional information
The text was updated successfully, but these errors were encountered: