我是新的项目计时,并试图运行教程,但陷入了第一个。代码如下:
#include "chrono/physics/ChLinkMotorRotationSpeed.h"
#include "chrono/physics/ChSystemNSC.h"
using namespace chrono;
int main(int argc, char* argv[]) {
GetLog() << "Copyright (c) 2017 projectchrono.org\nChrono version: " << CHRONO_VERSION << "\n\n";
{
//
// EXAMPLE 1:
//
GetLog() << " Example: create a physical system.. \n";
// The physical system: it contains all physical objects.
ChSystemNSC sys;
// Create a bunch of rigid bodies..
// Note that we use shared pointers, so you don't
// have to care about the deletion (never use delete.. for
// objects managed with shared pointers! it will be automatic!)
auto my_body_A = chrono_types::make_shared<ChBody>();
auto my_body_B = chrono_types::make_shared<ChBody>();
auto my_body_C = chrono_types::make_shared<ChBody>();
// Create some markers..
// Markers are 'auxiliary coordinate systems' to be added
// to rigid bodies.
// Again, note that they are managed by shared pointers.
auto my_marker_a1 = chrono_types::make_shared<ChMarker>();
auto my_marker_a2 = chrono_types::make_shared<ChMarker>();
auto my_marker_b1 = chrono_types::make_shared<ChMarker>();
auto my_marker_b2 = chrono_types::make_shared<ChMarker>();
// You can create some forces too...
auto my_force_a1 = chrono_types::make_shared<ChForce>();
auto my_force_a2 = chrono_types::make_shared<ChForce>();
// Here you will add forces and markers to rigid
// bodies.
// Note: the same marker shouldn't be added to multiple bodies.
my_body_A->AddMarker(my_marker_a1);
my_body_A->AddMarker(my_marker_a2);
my_body_A->AddForce(my_force_a1);
my_body_A->AddForce(my_force_a2);
my_body_B->AddMarker(my_marker_b1);
my_body_B->AddMarker(my_marker_b2);
// Ok, remember that rigid bodies must be added to
// the physical system.
sys.AddBody(my_body_A);
sys.AddBody(my_body_B);
sys.AddBody(my_body_C);
// Show the hierarchy in the shell window...
GetLog() << "Here's the system hierarchy which you built: \n\n ";
sys.ShowHierarchy(GetLog());
// Do you want to remove items? Use the
// Remove...() functions.
my_body_A->RemoveAllForces();
// Remove a single body..
sys.RemoveBody(my_body_A);
// Add markers to another body...
my_body_B->AddMarker(my_marker_a1);
my_body_B->AddMarker(my_marker_a2);
my_body_B->AddForce(my_force_a1);
my_body_B->AddForce(my_force_a2);
// By the way, you can set an Ascii name for objects as desired:
my_marker_a1->SetName("JohnFoo");
// ..so you can later use my_body_B.SearchMarker("JohnFoo"); etc.
GetLog() << "\n\n\nHere's the system hierarchy after modifications: \n\n ";
sys.ShowHierarchy(GetLog());
}
return 0;
}
字符串
我添加了所有需要的模块,库和dll到项目中,所以现在我没有得到与它们相关的错误消息,但得到了一个异常,我现在不知道如何处理。此异常仅在代码完成时且在“return 0”之前发生。我的想法是,异常的发生是因为共享指针被删除了两次,但我不确定是不是这样。
下面是我在Visual Studio的'memory'文件中得到的异常消息:
- 在ConsoleApplication7.exe中的0x00007FFF6E0ECA3E(ChronoEngine.dll)处引发异常:0xC0000005:访问冲突写入位置0x00000185243FCA0F*
内存文件中抛出异常的部分如下:
void _Destroy() noexcept override { // destroy managed resource
delete _Ptr;
}
型
1条答案
按热度按时间gc0ot86w1#
我认为问题是在您删除后标记仍然链接到
my_body_A
。当您尝试将其添加到my_body_B
时,此链接会导致异常。您应该创建新标记以添加到
my_body_B
:字符串