PDA

View Full Version : Program Crash



jonmatteo
17th June 2009, 13:22
Hi all,
I have implemented a C++ function that uses a C library. I have no problem if i call it from main but when i call it whitin a QWidget the program crashes.
Any help?
Thanks

spirit
17th June 2009, 13:29
check line 45 in your source.
no, seriously provide more information and code.

jonmatteo
17th June 2009, 14:12
ok
the function i have to call il


void run()
{
MesDomain *domain;
domain=new MesDomain();
std::vector<MesPoint> p;
std::vector<MesEndPoints> s;
std::vector<MesPoint> v;
...
domain->setPolygon(p,s,h);
domain->computeQuadrangulation();
...
delete domain
}


here is class MesDomain



class MesDomain
{
private:
MesPolygon *polygon;
MesNodes *nodes;
MesEdges *edges;
MesElements *elements;
CQMesh *mesh;

public:
MesDomain();
~MesDomain();

void setPolygon(std::vector<MesPoint>, std::vector<MesEndPoints>, std::vector<MesPoint> );
void computeQuadrangulation();
void saveQuadrangulation(std::string);

private:
void computeTriangulation(triangulateio *);
};


and its methods:


void MesDomain::setPolygon(std::vector<MesPoint> v, std::vector<MesEndPoints> s, std::vector<MesPoint> h) {
for (std::vector<MesPoint>::iterator it=v.begin(); it!=v.end(); ++it) polygon->addVertex(*it);
for (std::vector<MesEndPoints>::iterator it=s.begin(); it!=s.end(); ++it) polygon->addSegment(*it);
for (std::vector<MesPoint>::iterator it=h.begin(); it!=h.end(); ++it) polygon->addHole(*it);
}




void MesDomain::computeQuadrangulation() {

triangulateio *triangulation;
triangulation = new triangulateio;
...
computeTriangulation(triangulation);
...
}





void MesDomain::computeTriangulation(triangulateio *out) {

triangulateio in;
...
char * opt = ...;
triangulate(opt, &in, out, 0);
}


and triangulateio and triangulate are defined in the C library

spirit
17th June 2009, 14:17
put a break point and check all variables. maybe some of pointers are equal to "0".


void MesDomain::computeTriangulation(triangulateio *out) {

triangulateio in;
...
char * opt = ...;//<--- put a break point here

Lykurg
17th June 2009, 14:23
I have no problem if i call it from main but when i call it whitin a QWidget the program crashes.

After you call "delete domain" in run() you maybe try to access any variable/function of that class? This would explain, why in main() you don't get an error, since there you don't delete it (of just leave the application afterward).

jonmatteo
17th June 2009, 15:47
thank you all
I cant get what was the problem but now i can run it
probably some empty pointer
Thanks