-
Segmentation fault?
Take a look at the following code:
Code:
typedef std::vector<unsigned int> VecUnsRAM;
VecUnsRAM myPos(vertices.size());
unsigned int count=0;
for(unsigned int j=0; j<vertices.size();++j) {
myP t=std::make_pair(count, vertices[j].D);
std::cout<<"Got here"<<std::endl;
PQ[j]=t;
std::cout<<"Got here"<<std::endl;
myPos[j]=count;// or myPos[j]=j; produces Seg fault error
std::cout<<"Got here"<<std::endl;
++count;
}
The output is "Got here" twice, and then the Seg fault. Any ideas why this happens?
Thanks
-
Progress on answering this has begun elsewhere.
-
Unfortunately, that was not a good answer. Your idea?
-
Look at the last link in laserlight's signature.
-
> Take a look at the following code:
A meaningless exercise, when you're dealing with segfaults.
It is highly likely that your problems started earlier in the program, and this is just where the problem shows up.
Clone the project then
- delete all the code that cannot have run until this moment
- simplify the test case so there is less code and less data to deal with (deleting yet more code).
While you're busy deleting, make sure it still crashes in the same place, for the same reason.
When you're done, you can post your simpler program in its entirety, and your simple test case. Only then would we have a reasonable chance of spotting cause and effect.