Reputation: 4398
I have the following struct:
struct FeatureMatch {
int id1, id2;
double score;
};
which runs fine when called by this function:
void ssdMatchFeatures(const FeatureSet &f1, const FeatureSet &f2, vector<FeatureMatch> &matches, double &totalScore) {
int m = f1.size();
int n = f2.size();
matches.resize(15000);
totalScore = 0;
double d;
double dBest;
int idBest;
printf("2");
for (int i=0; i<m; i++) {
dBest = 1e100;
idBest = 0;
for (int j=0; j<n; j++) {
d = distanceSSD(f1[i].data, f2[j].data);
if (d < dBest) {
dBest = d;
idBest = f2[j].id;
}
}
printf("1\n");
matches[i].id1 = f1[i].id;
matches[i].id2 = idBest;
matches[i].score = -dBest;
// matches[i].second=1;
totalScore += matches[i].score;
}
printf("3");
}
However, as soon as I modify the struct by adding a new element:
struct FeatureMatch {
int id1, id2;
double score, second;
};
An additional double value called second makes the above function crash on segmentation error. The output of 1,2,3 shows something like:
21 1 1 1 1 . . . 1
But never gets to 3 before it crashes.
what is going on here? Even if I never modify matches[i].second, this happens.
Upvotes: 1
Views: 217
Reputation: 179552
If you change a structure definition, you should rebuild all affected source files if your build tool doesn't automatically do so. Otherwise, you may link together modules that use different definitions for the structure, which will result in confusing bugs (as you have seen).
Upvotes: 1