简体   繁体   English

功能结束后出现段错误(C ++)

[英]seg fault after end of function (C++)

I'm having a seg fault: 11 when I run a particular program. 我遇到段错误:11运行特定程序时。 I feel like this problem wasn't present before I upgraded my system to Mac OS X 10.9, but it's possible I just overlooked it.. 在将系统升级到Mac OS X 10.9之前,我觉得这个问题并不存在,但是有可能我只是忽略了它。

Anyway, my function looks like: 无论如何,我的函数看起来像:

// 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;

}

where the cout line at the end was just checking to see I'd got to the end of the function properly (which I have). 末尾的cout行只是在检查我是否正确到达了函数的结尾(我知道)。 Any thoughts on why this would be segfaulting here? 有什么想法为什么会在这里出现段错误? I appreciate it might be hard to tell without seeing what the individual function calls do, and so I'll add those if necessary. 我知道,可能不知道单个函数调用的作用就很难分辨,因此,如有必要,我将添加它们。

It doesn't actually matter too much, as this function is the last thing to be called (so the seg fault doesn't interrupt anything), but I still would rather get to the bottom of it! 实际上并没有太大关系,因为此函数是最后一个要调用的函数(因此seg错误不会中断任何操作),但是我还是想深入了解它!

The only thing that happens "after" the function are destructor calls. 函数“之后”发生的唯一事情是析构函数调用。 Check all your destructors of local variables. 检查所有局部变量的析构函数。 It looks like ObjectiveFunction is the only local variable that's not a primitive or standard library container, so check ObjectiveFunction::~ObjectiveFunction() for potential problems. 看来, ObjectiveFunction是唯一不是原始库或标准库容器的局部变量,因此请检查ObjectiveFunction::~ObjectiveFunction()以了解潜在的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM