James,

This is such a complicated setup to reproduce the error you mention that I 
suspect it may have nothing to do with Chrono itself (especially since I was 
unable to reproduce it with VS on Windows or GCC on Linux).  You will need to 
show us how we can reproduce this with an MRE, not with a scenario that 
introduces so many unknowns (to say nothing of the extra work it’d require any 
of us to replicate your very particular setup).

--Radu

From: [email protected] <[email protected]> On Behalf 
Of James Baxter
Sent: Tuesday, 28 February 2023 20:20
To: ProjectChrono <[email protected]>
Subject: Re: [chrono] Double free caused by use of HMMWV and LinkLocks

Hi Radu,

I run this using an Ubuntu container running on Podman (a Docker alternative). 
I have attached the files I use to generate it, which will allow you to 
replicate my environment.

Instructions to reproduce:
- Install Podman (Docker should also replicate the issue, but you will need to 
rename 'Containerfile' to 'Dockerfile', and replace every 'podman' with 
'docker'). It should work just fine on WSL 2.
- Download the 3 files to a folder you can access from WSL and `cd` into it
- Build the container: `podman build -t chrono .`
- Run the container: `podman run --rm -it -v $PWD:/root/code -w /root/code 
chrono`
- (inside the container) Build: `mkdir build && cd build && cmake .. && make`
- (inside the container) Run: `./chrono_crash`

If you aren't familiar with containerization, please note that the command to 
run the container mounts the current folder to /root/code in the container. So 
if you add files there, they persist on your machine. If you run the command in 
a folder already containing data, then delete the data in the folder from 
within the container, it will be similarly deleted on your machine. Therefore, 
I suggest making a new empty folder to add these files and operate it. Also, 
you can exit the container with CLRL+D.

Let me know if you have any issues

On Saturday, February 25, 2023 at 3:50:33 AM UTC-5 Radu Serban wrote:
James, I am unable to reproduce this (on Windows using VS 2022 v.17.4.4 and on 
Ubuntu 22.04 (WSL) using GCC 11.3.0).
I take it you are using GCC. What version? Are you linking any additional 
libraries to your Chrono build? Any changes to CMakeLists or to compiler flags?
--Radu

From: [email protected] <[email protected]> On Behalf Of 
James Baxter
Sent: Thursday, 23 February 2023 23:25
To: ProjectChrono <[email protected]>
Subject: [chrono] Double free caused by use of HMMWV and LinkLocks

I've encountered a memory error that I can't seem to figure out. It seems to be 
that the HMMWV_Full destructors cause the (internal to the suspension) LinkLock 
destructors to do a double free, only if a link lock class is referenced (but 
not necessarily used) in the class. Here is a minimal example:

#include <chrono_models/vehicle/hmmwv/HMMWV.h>
#include <chrono/physics/ChLinkLock.h>

using namespace chrono;
using namespace chrono::vehicle;
using namespace chrono::vehicle::hmmwv;

void foo() {
    auto bar = chrono_types::make_shared<ChLinkLockRevolute>();
}

int main(int argc, char* argv[]) {
    HMMWV_Full my_hmmwv;
    my_hmmwv.SetContactMethod(ChContactMethod::SMC);
    my_hmmwv.SetChassisCollisionType(CollisionType::NONE);
    my_hmmwv.SetChassisFixed(false);
    my_hmmwv.SetInitPosition(CSYSNORM);
    my_hmmwv.SetPowertrainType(PowertrainModelType::SHAFTS);
    my_hmmwv.SetDriveType(DrivelineTypeWV::AWD);
    my_hmmwv.UseTierodBodies(true);
    my_hmmwv.SetSteeringType(SteeringTypeWV::PITMAN_ARM);
    my_hmmwv.SetBrakeType(BrakeType::SHAFTS);
    my_hmmwv.SetTireType(TireModelType::TMEASY);
    my_hmmwv.SetTireStepSize(1e-3);
    my_hmmwv.Initialize();

    return 0;
}

You can see that the function `foo` isn't even called, yet it's existence 
causes the crash. If commented out, there are no issues. Here is the output 
(development branch):
Chrono was not built with Thrust support. CHRONO collision system type not 
available.
double free or corruption (out)
Aborted

I've attached Valgrind output too, which is more detailed. I'm hoping that 
there is something really simple or obvious that I'm missing here. Thanks in 
advance for any help figuring this out.

--
You received this message because you are subscribed to the Google Groups 
"ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/projectchrono/43a25eec-b573-493e-ae60-04dc1b2c899dn%40googlegroups.com<https://groups.google.com/d/msgid/projectchrono/43a25eec-b573-493e-ae60-04dc1b2c899dn%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups 
"ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/projectchrono/3f0ba9ad-f94d-4cb1-813e-e61b79fbdf0an%40googlegroups.com<https://groups.google.com/d/msgid/projectchrono/3f0ba9ad-f94d-4cb1-813e-e61b79fbdf0an%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/projectchrono/PH0PR06MB8237F0AD24E19EF058ED8E1AA7B39%40PH0PR06MB8237.namprd06.prod.outlook.com.

Reply via email to