2014-02-12 60 views
1

我在运行特定程序时出现seg错误:11。我觉得像我之前升级我的系统的Mac OS X 10.9这个问题是不存在的,但它可能只是我忽略了它..函数结束后的seg fault(C++)

无论如何,我的函数看起来像:

// this applies a warp to the field given, and saves output. simple! 
void Apply(string warpName, string fieldName, bool conserve, string outName) { 

    // get lon, lat dimensions of warp 
    int noLongs = GetDimension(warpName, 3, "warp"); 
    int noLats = GetDimension(warpName, 2, "warp"); 

    int origNoLongs = noLongs, origNoLats = noLats; 

    // read in params 
    vector<double> params = ImportWarpFromNetCDF(warpName); 

    // rescale field to warp's dimensions, and read in 
    string tempName = "scaledField"; 
    ReScale(fieldName, tempName, noLongs, noLats); 
    vector<vector<vector<double> > >inIntensities = ImportFieldFromNetCDF(tempName); 
    RemoveFile(tempName); 

    // just enter inIntensities for ref image, and 1 for lambda, to keep objective function happy 
    ObjectiveFunction objective(inIntensities, inIntensities, conserve, 1, false); 
    objective.setParameters(params); 

    // output files 
    ExportOutputToNetCDF(objective, outName); 

    cout << "BAH?!" << endl; 

} 

其中COUT最后一行只是检查我是否已经正确地结束了函数(我有)。任何想法为什么这将在这里segfaulting?我很欣赏可能很难说没有看到个别函数调用了什么,所以我会在必要时添加这些函数。

它实际上并没有太大的关系,因为该功能被称为(所以赛格故障不会中断任何东西)的最后一件事,但我还是宁愿得到它的底部!

+0

如果'cout'之后,但返回的功能之前,那么这将是在局部变量之一的析构函数的段错误发生。你的调试器应该告诉你它到底发生了什么。 –

回答

5

出现这种情况的唯一的事“之后”的功能是析构函数调用。检查所有局部变量的析构函数。它看起来像ObjectiveFunction是唯一不是原始或标准库容器的局部变量,因此请检查ObjectiveFunction::~ObjectiveFunction()是否存在潜在问题。

+1

非常出色 - 在〜ObjectiveFunction中有一个调用来删除一个没有为这种类型的ObjectiveFunction设置的指针!我现在已经将这个删除包装在if子句中,这样我们就不会尝试删除那些不存在的东西。非常感谢! – tiswas