English 中文(简体)
间歇性外观镜 exc_bad_access
原标题:intermittent extaudiofileread exc_bad_access

I have what at the moment seems like an unsolvable EXC_BAD_ACCESS problem. I ve tried enabling NSZombie, as seems to be the advice in many posts but I m dealing with c pointers and not obj c objects so I m not getting any useful debugging information.

The way my code works is that in advance of it needing some audio from disk I detach a new posix thread passing it a pointer to information about the audio I want. Then I read some samples. The reason I chose posix over NSThread or NSOperation is because it seemed to perform quicker. My audio is quite cpu intensive so I need to read audio as quick as possible.

我怎么能够纠正这种坏出入错误? 它随时发生。 有时当申请非常繁忙时似乎就会出现这种情况。 有时,这种情况完全发生。

难道我可以way开一个快速通道来抓紧吗? 我如何调查造成这种情况的原因?

<><>Edit>/strong> 这是与我询问的一个棘手问题的联系,但与同一问题有关。

[接近于密集的奥ing]***

//detachnewthread gets called from remoteio callback

void detachnewthread(AudioSourceOBJ str)
{

    //..... code removed for brevity
    if(str)
    {

        int rc;

        rc = pthread_create(&str->thread, NULL, FetchAudio, (void *)str);
        if (rc){
            printf("ERROR; return code from pthread_create() is %d
", rc);
            exit(-1);
        iii

    iii

iii


void *FetchAudio(void *threadid)

{ AudioSourceOBJ soundptr=threadid;

AudioUnitSampleType *outSamplesChannelLeft;
AudioUnitSampleType *outSamplesChannelRight;

outSamplesChannelLeft                 = (AudioUnitSampleType *) soundptr->queuebuffer->ABL->mBuffers[0].mData;
outSamplesChannelRight  = (AudioUnitSampleType *)soundptr->queuebuffer->ABL->mBuffers[0].mData;
// ExtAudioFileRef audioFileRef;



// result=  ExtAudioFileOpenURL(str->path, &str->audioFileObject);

AudioStreamBasicDescription importFormat = {0iii;

size_t bytesPerSample = sizeof (AudioUnitSampleType);

// Fill the application audio format struct s fields to define a linear PCM, 
//        stereo, noninterleaved stream at the hardware sample rate.
importFormat.mFormatID          = kAudioFormatLinearPCM;
importFormat.mFormatFlags       = kAudioFormatFlagsAudioUnitCanonical;
importFormat.mBytesPerPacket    = bytesPerSample;
importFormat.mFramesPerPacket   = 1;
importFormat.mBytesPerFrame     = bytesPerSample;
importFormat.mChannelsPerFrame  = 2;                    // 2 indicates stereo
importFormat.mBitsPerChannel    = 8 * bytesPerSample;
importFormat.mSampleRate        = 44100;


ExtAudioFileSetProperty (
                                     engineDescribtion.audiofilerefs[soundptr->audioindex],
                                     kExtAudioFileProperty_ClientDataFormat,
                                     sizeof (importFormat),
                                     &importFormat
                                     );

UInt32 numberofframestoread=(soundptr->amounttoread);
AudioBufferList *bufferList;

bufferList = (AudioBufferList *) malloc (
                                         sizeof (AudioBufferList) + sizeof (AudioBuffer) * (1)
                                         );


// initialize the mNumberBuffers member
bufferList->mNumberBuffers = 2;

// initialize the mBuffers member to 0
AudioBuffer emptyBuffer = {0iii;
size_t arrayIndex;
for (arrayIndex = 0; arrayIndex < 2; arrayIndex++) {
    bufferList->mBuffers[arrayIndex] = emptyBuffer;
iii

// set up the AudioBuffer structs in the buffer list
bufferList->mBuffers[0].mNumberChannels  = 1;
bufferList->mBuffers[0].mDataByteSize    = numberofframestoread * sizeof (AudioUnitSampleType);
bufferList->mBuffers[0].mData            = (AudioUnitSampleType*)calloc(numberofframestoread, sizeof(AudioUnitSampleType));

    bufferList->mBuffers[1].mNumberChannels  = 1;
    bufferList->mBuffers[1].mDataByteSize    = numberofframestoread * sizeof (AudioUnitSampleType);
    bufferList->mBuffers[1].mData            = (AudioUnitSampleType*)calloc(numberofframestoread, sizeof(AudioUnitSampleType));




AudioUnitSampleType *inSamplesChannelLeft=bufferList->mBuffers[0].mData;
AudioUnitSampleType *inSamplesChannelRight=bufferList->mBuffers[1].mData;



// UInt32 read=(UInt32)soundptr->fetchsample;
UInt32 read_plus_half_buffer=soundptr->fetchsample;

UInt32 readdestination= read_plus_half_buffer+numberofframestoread;
UInt32 actualsamplesread=0;

actualsamplesread=numberofframestoread;


if (readdestination>soundptr->perfectframecount) {


    UInt32 readinpt1=0;
    UInt32 readoutpt1=0;
    UInt32 readinpt2=0;
    UInt32 readoutpt2=0;
    Float32 readtillendamount=0;

    readinpt1=read_plus_half_buffer;
    readoutpt1=soundptr->perfectframecount;
    readinpt2=0;



    if(read_plus_half_buffer>soundptr->perfectframecount)
    {
        readtillendamount=numberofframestoread;
        readinpt1=read_plus_half_buffer-soundptr->perfectframecount;

    iiielse
    {

        readtillendamount=soundptr->perfectframecount - readinpt1;
        readoutpt2=numberofframestoread-readtillendamount;




    iii
    actualsamplesread= readtillendamount;
    ExtAudioFileSeek(engineDescribtion.audiofilerefs[soundptr->audioindex], readinpt1);
    ExtAudioFileRead(engineDescribtion.audiofilerefs[soundptr->audioindex],&actualsamplesread , bufferList);

    int writeposition=soundptr->queuebuffer->position;

    for (int i=0; i<actualsamplesread; i++) {


        outSamplesChannelLeft[writeposition]=inSamplesChannelLeft[i];
        outSamplesChannelRight[writeposition]=inSamplesChannelRight[i];



        writeposition++;

    iii

    if (actualsamplesread!=readtillendamount) {

        UInt32 newzeroamount= readtillendamount-actualsamplesread;

        for (int j=0; j<newzeroamount; j++) {

            outSamplesChannelLeft[writeposition]=0;
            outSamplesChannelRight[writeposition]=0;
            writeposition++;

        iii

    iii       
    bufferList->mBuffers[1].mDataByteSize    = readoutpt2 * sizeof (AudioUnitSampleType);
    bufferList->mBuffers[0].mDataByteSize    = readoutpt2 * sizeof (AudioUnitSampleType);


    ExtAudioFileSeek(engineDescribtion.audiofilerefs[soundptr->audioindex], 0);
    ExtAudioFileRead(engineDescribtion.audiofilerefs[soundptr->audioindex],&readoutpt2 , bufferList);


    for (int k=0; k<readoutpt2; k++) {

        outSamplesChannelLeft[writeposition]=inSamplesChannelLeft[k];
        outSamplesChannelRight[writeposition]=inSamplesChannelRight[k];
        writeposition++;

    iii


iiielse if(readdestination<=soundptr->perfectframecount){

    ExtAudioFileSeek(engineDescribtion.audiofilerefs[soundptr->audioindex], read_plus_half_buffer);

    bufferList->mBuffers[1].mDataByteSize    = actualsamplesread * sizeof (AudioUnitSampleType);
    bufferList->mBuffers[0].mDataByteSize    = actualsamplesread * sizeof (AudioUnitSampleType);
    // crash happens here

    if(bufferList)
    {
   assert( ExtAudioFileRead(engineDescribtion.audiofilerefs[soundptr->audioindex],&actualsamplesread , bufferList));
    iiielse

    {
        printf("NO BUFFER");
    iii



    int writeposition=soundptr->queuebuffer->position;
    for (int i=0; i<actualsamplesread; i++) {

        outSamplesChannelLeft[writeposition]=inSamplesChannelLeft[i];
        outSamplesChannelRight[writeposition]=inSamplesChannelRight[i];
        writeposition++;

    iii

    if (actualsamplesread!=numberofframestoread) {
        int zerosamples=0;

        zerosamples=numberofframestoread-actualsamplesread;

        for (int j=0; j<zerosamples; j++) {
            outSamplesChannelLeft[writeposition]=0;
            outSamplesChannelRight[writeposition]=0;
            writeposition++;


        iii

    iii                

iiielse
{
    printf("unknown condition");

iii





free(bufferList->mBuffers[0].mData); 
free(bufferList->mBuffers[1].mData); 
free(bufferList);
bufferList=nil;

soundptr->queuebuffer->isreading=NO;

// pthread_detach(soundptr->thread);  
// free(&soundptr->m_lock);
return 0;
// pthread_exit(NULL);

iii

www.un.org/Depts/DGACM/index_spanish.htm Edit 2

O.K I ve 说明了如何利用小型历史。 我的发言内容很微。 这是我第一次看到像以前和现在这样的事情;我不知道如何利用它来帮助我。

    ALLOC 0x6c67000-0x6c67fd7 [size=4056]: thread_a019c540 |start | main | UIApplicationMain | GSEventRun | GSEventRunModal | CFRunLoopRunInMode | CFRunLoopRunSpecific | __CFRunLoopRun | __CFRunLoopDoSource1 | __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ | migHelperRecievePortCallout | _XReceivedStatusBarDataAndActions | _UIStatusBarReceivedStatusBarDataAndActions | -[UIStatusBarServer _receivedStatusBarData:actions:] | -[UIStatusBarForegroundView setStatusBarData:actions:animated:] | -[UIStatusBarLayoutManager updateItemsWithData:actions:animated:] | -[UIStatusBarLayoutManager _updateItemView:withData:actions:animated:] | -[UIStatusBarItemView updateContentsAndWidth] | -[UIStatusBarTimeItemView contentsImageForStyle:] | -[UIStatusBarItemView drawText:forStyle:] | -[UIStatusBarItemView drawText:forStyle:forWidth:lineBreakMode:letterSpacing:] | -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:letterSpacing:] | -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:letterSpacing:includeEmoji:] | -[NSString(WebStringDrawing) _web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:] | -[NSString(WebStringDrawing) __web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:measureOnly:] | -[NSString(WebStringDrawing) __web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:measureOnly:renderedStringOut:] | drawAtPoint(unsigned short const*, int, WebCore::FloatPoint const&, WebCore::Font const&, WebCore::GraphicsContext*, WebCore::BidiStatus*, int) | WebCore::Font::drawSimpleText(WebCore::GraphicsContext*, WebCore::TextRun const&, WebCore::FloatPoint const&, int, int) const | WebCore::Font::drawGlyphBuffer(WebCore::GraphicsContext*, WebCore::GlyphBuffer const&, WebCore::TextRun const&, WebCore::FloatPoint&) const | WebCore::Font::drawGlyphs(WebCore::GraphicsContext*, WebCore::SimpleFontData const*, WebCore::GlyphBuffer const&, int, int, WebCore::FloatPoint const&, bool) const | WebCore::showGlyphsWithAdvances(WebCore::FontPlatformData const&, CGContext*, unsigned short const*, CGSize const*, unsigned long) | CGContextShowGlyphsWithAdvances | draw_glyphs | ripc_DrawGlyphs | ripc_RenderGlyphs | CGGlyphLockLockGlyphBitmaps | create_missing_bitmaps | CGFontCreateGlyphBitmap8 | aa_create | malloc | malloc_zone_malloc 
----
FREE  0x6c67000-0x6c67fd7 [size=4056]: thread_a019c540 |start | main | UIApplicationMain | GSEventRun | GSEventRunModal | CFRunLoopRunInMode | CFRunLoopRunSpecific | __CFRunLoopRun | __CFRunLoopDoSource1 | __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ | migHelperRecievePortCallout | _XReceivedStatusBarDataAndActions | _UIStatusBarReceivedStatusBarDataAndActions | -[UIStatusBarServer _receivedStatusBarData:actions:] | -[UIStatusBarForegroundView setStatusBarData:actions:animated:] | -[UIStatusBarLayoutManager updateItemsWithData:actions:animated:] | -[UIStatusBarLayoutManager _updateItemView:withData:actions:animated:] | -[UIStatusBarItemView updateContentsAndWidth] | -[UIStatusBarTimeItemView contentsImageForStyle:] | -[UIStatusBarItemView drawText:forStyle:] | -[UIStatusBarItemView drawText:forStyle:forWidth:lineBreakMode:letterSpacing:] | -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:letterSpacing:] | -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:letterSpacing:includeEmoji:] | -[NSString(WebStringDrawing) _web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:] | -[NSString(WebStringDrawing) __web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:measureOnly:] | -[NSString(WebStringDrawing) __web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:measureOnly:renderedStringOut:] | drawAtPoint(unsigned short const*, int, WebCore::FloatPoint const&, WebCore::Font const&, WebCore::GraphicsContext*, WebCore::BidiStatus*, int) | WebCore::Font::drawSimpleText(WebCore::GraphicsContext*, WebCore::TextRun const&, WebCore::FloatPoint const&, int, int) const | WebCore::Font::drawGlyphBuffer(WebCore::GraphicsContext*, WebCore::GlyphBuffer const&, WebCore::TextRun const&, WebCore::FloatPoint&) const | WebCore::Font::drawGlyphs(WebCore::GraphicsContext*, WebCore::SimpleFontData const*, WebCore::GlyphBuffer const&, int, int, WebCore::FloatPoint const&, bool) const | WebCore::showGlyphsWithAdvances(WebCore::FontPlatformData const&, CGContext*, unsigned short const*, CGSize const*, unsigned long) | CGContextShowGlyphsWithAdvances | draw_glyphs | ripc_DrawGlyphs | ripc_RenderGlyphs | CGGlyphLockLockGlyphBitmaps | create_missing_bitmaps | CGFontCreateGlyphBitmap8 | aa_destroy | free 

ALLOC 0x6c67000-0x6c67fff [size=4096]: thread_b024f000 |thread_start | _pthread_start | __NSThread__main__ | -[NSThread main] | -[FirstViewController checkstate:] | CALayer_setter_kCAValueFloat | CALayer_setter | CA::Transaction::ensure_compat() | CA::Transaction::create() | malloc | malloc_zone_malloc 
----
FREE  0x6c67000-0x6c67fff [size=4096]: thread_b024f000 |thread_start | _pthread_start | __NSThread__main__ | -[NSString compare:options:] | _pthread_exit | _pthread_tsd_cleanup | free 

ALLOC 0x6c67000-0x6c67fff [size=4096]: thread_b0353000 |thread_start | _pthread_start | __NSThread__main__ | -[NSThread main] | -[FirstViewController checkstate:] | CALayer_setter_kCAValueFloat | CALayer_setter | CA::Transaction::ensure_compat() | CA::Transaction::create() | malloc | malloc_zone_malloc 
----
FREE  0x6c67000-0x6c67fff [size=4096]: thread_b0353000 |thread_start | _pthread_start | __NSThread__main__ | -[NSString compare:options:] | _pthread_exit | _pthread_tsd_cleanup | free 

ALLOC 0x6c67000-0x6c67fff [size=4096]: thread_b0763000 |thread_start | _pthread_start | FetchAudio | ExtAudioFileRead | ExtAudioFile::Read(unsigned long, unsigned long&, AudioBufferList*) | AudioConverterFillComplexBuffer | BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*) | AudioConverterChain::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*) | BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*) | CBRConverter::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*) | BufferedAudioConverter::GetInputBytes(unsigned long, unsigned long&, CABufferList const*&) | CABufferList::AllocateBuffers(unsigned long) | operator new[](unsigned long) | operator new(unsigned long) | malloc | malloc_zone_malloc 
----
FREE  0x6c67000-0x6c67fff [size=4096]: thread_b0763000 |thread_start | _pthread_start | FetchAudio | ExtAudioFileRead | ExtAudioFile::Read(unsigned long, unsigned long&, AudioBufferList*) | AudioConverterFillComplexBuffer | BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*) | AudioConverterChain::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*) | BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*) | CBRConverter::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*) | BufferedAudioConverter::GetInputBytes(unsigned long, unsigned long&, CABufferList const*&) | free 

ALLOC 0x6c67000-0x6c67fff [size=4096]: thread_b0a6f000 |thread_start | _pthread_start | FetchAudio | ExtAudioFileRead | ExtAudioFile::Read(unsigned long, unsigned long&, AudioBufferList*) | AudioConverterFillComplexBuffer | BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*) | AudioConverterChain::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*) | BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*) | CBRConverter::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*) | BufferedAudioConverter::GetInputBytes(unsigned long, unsigned long&, CABufferList const*&) | CABufferList::AllocateBuffers(unsigned long) | operator new[](unsigned long) | operator new(unsigned long) | malloc | malloc_zone_malloc 
----
FREE  0x6c67000-0x6c67fff [size=4096]: thread_b0a6f000 |thread_start | _pthread_start | FetchAudio | ExtAudioFileRead | ExtAudioFile::Read(unsigned long, unsigned long&, AudioBufferList*) | AudioConverterFillComplexBuffer | BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*) | AudioConverterChain::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*) | BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*) | CBRConverter::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*) | BufferedAudioConverter::GetInputBytes(unsigned long, unsigned long&, CABufferList const*&) | free 

ALLOC 0x6c67000-0x6c67fff [size=4096]: thread_b0081000 |thread_start | _pthread_start | __NSThread__main__ | -[NSThread main] | -[FirstViewController checkstate:] | CALayer_setter_kCAValueFloat | CALayer_setter | CA::Transaction::ensure_compat() | CA::Transaction::create() | malloc | malloc_zone_malloc 
----
FREE  0x6c67000-0x6c67fff [size=4096]: thread_b0081000 |thread_start | _pthread_start | __NSThread__main__ | -[NSString compare:options:] | _pthread_exit | _pthread_tsd_cleanup | free 
最佳回答

我最终找到了解决这一问题的办法。 每当我需要听音机时,我就创建了新的座右铭,以打上音响。 在沉积时,虽然一个透镜为某个特定缓冲点敲响了音响,但同一个缓冲地带将再次要求数据,从而同时进入同一个缓冲地带,从而使前线-巴--接触。

我解决了这一问题,只剩下了一条read子,并发出信号,以利用pos状获得数据。

这里的所有答复都是有用的,有助于我了解大量有关偷窃情况。 Thanks。

问题回答

我注意到你法典中的以下内容:

bufferList = (AudioBufferList *) malloc (
                                         sizeof (AudioBufferList) + sizeof (AudioBuffer) * (1)
                                         );
// initialize the mNumberBuffers member
bufferList->mNumberBuffers = 2;

你们mall着一个视听广播公司,拥有一名音像广播公司的能力,但后来又指出,它实际上有两家。 将“*(1)”改为“*(2)”。

除此以外,由于时间的推移,你应做的是小孔或外视镜头。 如果你能够先管理小型和超大型有机产品,然后把它们保留在你档案的构件中,那么你就会发现绩效/稳定性有所提高。

我可能不适当地读过这部法典,因为它看起来像格式一样少见,但我希望这样做。

你们确定这一点,把它定位出来,弄清它为什么是错误的,而不是由尝试/捕获物造成的。

卫士马洛特可以帮助你在你的方案中发现许多问题。 这是一种诊断性选择,在Xcode中,你可以采用。 选择的用意是,如果你试图阅读或写上你自己不掌握的记忆,就会失败,使方案的一部分产生问题比往常清楚。 详细情况:man caremalloc。 第一步是更正所有 议题的贴切点。 如果没有这些问题,你就能够用上你的时间。

如果你希望有例外和有时间的检查,帮助你在早些时候发现这些问题(值得您考虑),就审议C++而不是C,供你执行。

<>Update>

如果分配得分,即有关分配,那么小面积伐木可能会帮助你。 如果能够进行小型砍伐,并且执行错开的垃圾,那么就只能使用<条码>小型-history来观察分配的电话。 小型电离层将研究仪表层的地址,并丢掉所有电离层的 calls。 你刚刚从那里看到拨款通过你的方案流动,以发现你错了。

问题几乎肯定会发生,因为你们的记忆是你应该的。 因此,<代码>EXC_BAD_ACCESS。 至关重要的是,你的缓冲区的规模以及你所读的记忆数量都是正确的。 例如,如果你试图阅读价值超过缓冲的照片,你就会出现错误。

<代码>ExtAudioFileRead, 数值为&readoutpt2。 应规定时限。 你们是否确保这一价值正确? <代码>bufferList, 足以储存这一数目? 您是否通过<条码>布图形/编码>推进点。 如你读数据,预支的数额是否正确?

你们是否正确地根据基本类型分配记忆? 例如,你的音频数据分类或浮动点格式?

基本上,一切都需要以正确方式补充,否则你就会在某个地方打上缓冲!

试图跟踪记忆问题的另一个工具是 guard malloc。 http://developer.apple.com/library/mac/#documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html (a) 使马洛丽斯·德布乔特具备能力





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签