Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 静态音频分析功能中的间歇性EXC_坏访问_C++_Ios_Audio_Reference_Objective C++ - Fatal编程技术网

C++ 静态音频分析功能中的间歇性EXC_坏访问

C++ 静态音频分析功能中的间歇性EXC_坏访问,c++,ios,audio,reference,objective-c++,C++,Ios,Audio,Reference,Objective C++,我正在编写一个使用实时音频分析的iOS应用程序。它有一个间歇性的崩溃(大约5分钟后,仅在模拟器上)。这意味着它与运输应用程序无关,但这对开发来说确实是一个痛苦,此外,如果我跟踪它,我晚上会睡得更好。崩溃总是在同一个地方发生,在我的音频分析代码中的静态函数中:崩溃发生在这里: struct Tone { // (other stuff) // THIS is the problem function: static bool dbCompare(Tone const& l, Tone c

我正在编写一个使用实时音频分析的iOS应用程序。它有一个间歇性的崩溃(大约5分钟后,仅在模拟器上)。这意味着它与运输应用程序无关,但这对开发来说确实是一个痛苦,此外,如果我跟踪它,我晚上会睡得更好。崩溃总是在同一个地方发生,在我的音频分析代码中的静态函数中:崩溃发生在这里:

struct Tone {
// (other stuff)

// THIS is the problem function:
static bool dbCompare(Tone const& l, Tone const& r) { return l.db < r.db; }
  }
};
哦,当然,这里的函数现在似乎是罪魁祸首:

- (void)timerCallback:(NSTimer *)timer {
  Tone const * tone = audio->analyzer->findTone();
  if (tone && tone->db > kToneMinDB) {
    self.currentPitch = tone->freq;
    self.currentVolume = tone->stabledb;
    self.currentNoteName = [NSString stringWithCString:scale->getNoteStr(tone->freq).c_str() encoding:NSUTF8StringEncoding];
//    NSLog(@"Current Note Name in timerCallback: %@", currentNoteName);
    self.currentNoteFunction = [pitchFilter getPitchFunctionFromPitchName:currentNoteName];
  } else {
    self.currentNoteName = @"--";
    self.currentNoteFunction = -1;
  }
}

我不明白程序如何在没有有效音调的情况下输入
if(tone)
块,或者相反,如果音调有效,程序如何崩溃。帮助

(这越来越长了。我是否应该删除其中的一些内容,以服务于更集中的问题?)

我在想: 1.这是一个线程问题::抖动::其中一个线程正在更改音频数据,而另一个线程正在读取它。 2.我不知道,timerCallback函数中有什么东西正在破坏堆栈,因为它分配的太频繁了。这个函数调用了很多次,但不是非常多;它计划每150毫秒调用一次


不确定为什么在模拟器中会有这两个问题,但在设备上没有问题。

< P>一个C++引用永远不能是代码>0 <代码> >代码> null <代码>。如果是,你已经进入了未定义的领域。如果参数可能是“代码> 0 ”,则必须将测试移至执行链。

也就是说,
dbCompare
的唯一格式良好的版本如下所示:

struct Tone {
    static bool dbCompare(Tone const& l, Tone const& r) {
        return l.db < r.db;
    }
};
struct音调{
静态布尔数据比较(音调常数和l、音调常数和r){
返回l.db
更新

如果在迭代时调整迭代器的大小,则迭代器将无效--我看不到此实现中会发生这种情况。是否从另一个线程调整容器的大小


另外,试着用GuardMalloc运行它-它的目的是让这些问题对你来说很明显。如果失败得越早,它对实现的影响就越大(在很多情况下).

我觉得'best=&*it'行很奇怪。容器是按引用还是按值存储的?看起来您可能正在返回临时存储的地址。这可能会导致问题。

这看起来很有希望绕过最新的障碍:好的,立即崩溃看起来像是一个iOS 5模拟器工件。请参阅above在4.3模拟器上进行跟踪。您是否“在malloc\u error\u break中设置断点以进行调试”?它指向什么?你的应用程序最终会耗尽内存-GuardMalloc不会释放,但这通常需要很长时间。是的,它指向我在OP@ickydog下一步有太多未定义的内容,我无法猜测。这可能是一个线程问题(正如我们现在都考虑过的)。此外,您是否意识到,如果这是在音频渲染回调中,则不应锁定?(无分配、无锁定、无objc消息)设备与sim卡是完全不同的环境—执行不同是有道理的。如果您的实现没有正确保护所需的内容,则会开始泄漏
#0  0x94f38c97 in malloc_error_break ()
#1  0x94efa4ce in szone_error ()
#2  0x94efc35f in allocate_pages ()
#3  0x94f013cc in allocate_pages_securely ()
#4  0x94f019b8 in szone_malloc_should_clear ()
#5  0x94f0266b in szone_malloc ()
#6  0x00331cc3 in GMmalloc_zone_malloc ()
#7  0x94f38edb in malloc_set_zone_name ()
#8  0x94f394a8 in _malloc_initialize ()
#9  0x94f3986b in malloc ()
#10 0x00002ef0 in start ()
#11 0x00013f1d in std::_List_const_iterator<Tone> std::max_element<std::_List_const_iterator<Tone>, bool (*)(Tone const&, Tone const&)>(std::_List_const_iterator<Tone>, std::_List_const_iterator<Tone>, bool (*)(Tone const&, Tone const&)) at /Developer/of_007_iphone/apps/cwi007/SingXO/SingXO/Pitch/pitch.hh:25
#12 0x000139b2 in Analyzer::findTone(double, double) const ()
#13 0x00011950 in -[AppDelegate timerCallback:] ()
#14 0x00115308 in -[CCTimer update:] ()
#15 0x0011e124 in -[CCScheduler tick:] ()
#16 0x0014993a in -[CCDirectorIOS drawScene] ()
#17 0x0014bda4 in -[CCDirectorDisplayLink mainLoop:] ()
#18 0x007baa88 in CA::Display::DisplayLink::dispatch(unsigned long long, unsigned long long) ()
#19 0x007babcd in CA::Display::EmulatorDisplayLink::callback(__CFRunLoopTimer*, void*) ()
#20 0x019c88c3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#21 0x019c9e74 in __CFRunLoopDoTimer ()
#22 0x019262c9 in __CFRunLoopRun ()
#23 0x01925840 in CFRunLoopRunSpecific ()
#24 0x01925761 in CFRunLoopRunInMode ()
#25 0x020bb1c4 in GSEventRunModal ()
#26 0x020bb289 in GSEventRun ()
#27 0x00beac93 in UIApplicationMain ()
#28 0x00002fb6 in main ()
GuardMalloc[MyApp-723]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
- (void)timerCallback:(NSTimer *)timer {
  Tone const * tone = audio->analyzer->findTone();
  if (tone && tone->db > kToneMinDB) {
    self.currentPitch = tone->freq;
    self.currentVolume = tone->stabledb;
    self.currentNoteName = [NSString stringWithCString:scale->getNoteStr(tone->freq).c_str() encoding:NSUTF8StringEncoding];
//    NSLog(@"Current Note Name in timerCallback: %@", currentNoteName);
    self.currentNoteFunction = [pitchFilter getPitchFunctionFromPitchName:currentNoteName];
  } else {
    self.currentNoteName = @"--";
    self.currentNoteFunction = -1;
  }
struct Tone {
    static bool dbCompare(Tone const& l, Tone const& r) {
        return l.db < r.db;
    }
};