I'm using Netbeans for my C++ project. The code crashed at the beginning of a function call. Trying to understand the cause of the crash, I did a 'Debug Core File' with gdb; the below is the message I came across. I'm trying to interpret what this means -
~"Program terminated with signal 11, Segmentation fault.\n"
~"[New process 10325]\n"
~"#0 0x0000000000ee00cc in CARRotorAerodynamics::Trim_Innerloop (this="
&"Cannot access memory at address 0x7fff71a70868\n"
~")\n"
~" at ../src/models/CARRotorAerodynamics.cpp:994\n"
~"994\tvoid CARRotorAerodynamics::Trim_Innerloop(CARHelicopter Helic)\n"
If I understand it correctly, the 'this' pointer of the instance of CARRotorAerodynamics is pointing to a faulty address 0x7fff71a70868. Is this so ?
The code I have is very long. A summary of the code is as below.
CARHelicopter.h
1 2 3 4 5 6 7 8 9 10 11 12 13
class CARHelicopter : public CARBase
{
public:
CARHelicopter();
virtual ~CARHelicopter();
CARRotorAerodynamics Rotor;
:
:
void Trim_HubLoads();
:
:
}
class CARHelicopter
class CARRotorAerodynamics : public CARBase
{
:
:
void Trim_Innerloop(CARHelicopter);
}
CARRotorAerodynamics.cpp
1 2 3 4 5 6 7 8 9
#include "CARRotorAerodynamics.h"
#include "CARHelicopter.h"
:
:
void CARRotorAerodynamics::Trim_Innerloop(CARHelicopter Helic) // PROGRAM CRASHES AT THIS LINE
{
}
The problem of Trim_Innerloop() is that it makes a copy of the passed object. If you have pointer within the passed object those pointers a copied and might be deleted.
This
void Trim_Innerloop(const CARHelicopter &Helic) // Note: const and &
will solve the problem (if the problem is the copy)
Tried as you suggest, but still getting the error.
The problem of Trim_Innerloop() is that it makes a copy of the passed object. If you have pointer within the passed object those pointers a copied and might be deleted.
Under what circumstances might the pointers of the passed object be deleted ?
I don't have any statements within the destructor.
For testing purpose, I modified the code a bit so that I didn't have to pass any object to the Trim_Innerloop function. Even in this case, the code crashed at the same line number. Which, perhaps, means that there is something wrong within the 'Rotor' object itself ?
The files are large, so I'm unable to post it here. Maybe later, I can send the files privately to you ? Thankyou for taking the time to look at the problem; really appreciate it.
The problem of Trim_Innerloop() is that it makes a copy of the passed object. If you have pointer within the passed object those pointers a copied and might be deleted.
This
void Trim_Innerloop(const CARHelicopter &Helic) // Note: const and &
will solve the problem (if the problem is the copy)
Thanks a lot, coder777. Your suggestion above worked. Apart from the function above, I have a lot of other functions where I have to pass objects as arguments. For eg.