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.
How can I fix this bad access error? It doesnt occur all of the time. Sometimes it seems to happen when the application is very busy. Very occasionally it doesnt happen at all.
Is there anyway I could just throw a try catch around this as a quick fix? How else can I investigate causes of this is happening?
Edit This is a link to a seperate question I asked but it is related to the same problem
[Threading for intense io][1]
//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\n", rc);
exit(-1);
}
}
}
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 = {0};
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 = {0};
size_t arrayIndex;
for (arrayIndex = 0; arrayIndex < 2; arrayIndex++) {
bufferList->mBuffers[arrayIndex] = emptyBuffer;
}
// 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;
}else
{
readtillendamount=soundptr->perfectframecount - readinpt1;
readoutpt2=numberofframestoread-readtillendamount;
}
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++;
}
if (actualsamplesread!=readtillendamount) {
UInt32 newzeroamount= readtillendamount-actualsamplesread;
for (int j=0; j<newzeroamount; j++) {
outSamplesChannelLeft[writeposition]=0;
outSamplesChannelRight[writeposition]=0;
writeposition++;
}
}
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++;
}
}else 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));
}else
{
printf("NO BUFFER");
}
int writeposition=soundptr->queuebuffer->position;
for (int i=0; i<actualsamplesread; i++) {
outSamplesChannelLeft[writeposition]=inSamplesChannelLeft[i];
outSamplesChannelRight[writeposition]=inSamplesChannelRight[i];
writeposition++;
}
if (actualsamplesread!=numberofframestoread) {
int zerosamples=0;
zerosamples=numberofframestoread-actualsamplesread;
for (int j=0; j<zerosamples; j++) {
outSamplesChannelLeft[writeposition]=0;
outSamplesChannelRight[writeposition]=0;
writeposition++;
}
}
}else
{
printf("unknown condition");
}
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);
}
Edit 2
O.K I've figured out how to use malloc history. I have a big trace statement. This is the first time I've ever seen anything like this before & I don't know how to use it to help myself.
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
I notice the following lines in your code:
bufferList = (AudioBufferList *) malloc (
sizeof (AudioBufferList) + sizeof (AudioBuffer) * (1)
);
// initialize the mNumberBuffers member
bufferList->mNumberBuffers = 2;
You are malloc'ing an AudioBufferList to have the capacity of one AudioBuffer, but then indicating that it actually has two. Try changing that "* (1)" to "* (2)".
In addition to this, you shouldn't perform malloc's or ExtAudioFileOpen's in the thread, as those will take up time. If you can manage to pre-perform the malloc's and ExtAudioFileOpen's and just keep them in a struct array for your files, you may find a increase in performance / stability.
I may not have read the code completely properly as it looks like the formatting got a little messed up, but I hope this helps.
You fix this by locating it and figuring out why it is wrong, not by a try/catch.
Guard Malloc can help you identify many issues in your program. It is a diagnostic option which you can enable in Xcode. The intent of the option is to fail when you attempt to read or write memory you do not own, making it clearer than usual which part of your program is causing issues. full details: man guardmalloc. The first step is to correct all issues guardmalloc points out. You should be able to run your app for hours without these issues.
If you want exceptions and runtime checks to help you identify these issues earlier on (which is worth your consideration), consider C++ rather than C for your implementations.
Update
if it's a heap allocation that is the allocation in question, then malloc logging will likely help you. when malloc logging is enabled and the debugger pauses execution, just use malloc_history to view the callstack for the allocation. malloc_history will lookup the address in the log and dump the callstack of the alloc's creation. from there, you just follow the allocation's flow through your program to find what you are getting wrong.
I eventually found the solution to this problem. Every time I needed audio I created a new thread to fetch the audio. On occassion while a thread was fetching audio for a particular the buffer the same buffer would request data again resulting in the same buffer be accessed at the same time, thus the exc_bad_access.
I solved this by having just one thread waiting and being signalled to get data using posix condition.
All of the answers here were useful and have helped me learn a lot about debugging. Thanks guys..
The problem is almost certainly happening because your reading memory that you shouldn't be. Hence the EXC_BAD_ACCESS. What's essential is that the sizes of your buffers, and the amount of memory that you are reading is all correct. For example if you try to read more than a buffer's worth, you'll receive an error.
In ExtAudioFileRead, the value at &readoutpt2 should specify the number of frames. Are you sure this value is correct? Is bufferList big enough to store that number of frames? Are you advancing a pointer through bufferList as you read data, and is the amount you advance correct?
Are you correctly allocating memory based upon the underlying type? For example is your audio data integer or floating point format?
Basically, everything needs to add up correctly otherwise you will blow a buffer somewhere!
One other tool to try for tracking down memory issues is guard malloc. You can find more info here Enabling the Malloc Debugging Features
Related
To check the existence of any threading issue I tried using Thread Sanitiser. But upon enabling it in Edit Scheme my app is crashing as soon as I launch the app. Below is the stack backtrace.
* thread #1, stop reason = signal SIGABRT
* frame #0: 0x0000000117791ad6 libsystem_kernel.dylib`__abort_with_payload + 10
frame #1: 0x00000001177933df libsystem_kernel.dylib`abort_with_payload_wrapper_internal + 80
frame #2: 0x000000011779338f libsystem_kernel.dylib`abort_with_reason + 19
frame #3: 0x00000001177d8c29 libsystem_pthread.dylib`pthread_self.cold.1 + 24
frame #4: 0x00000001177d2334 libsystem_pthread.dylib`pthread_self + 35
frame #5: 0x000000010ea1516b libclang_rt.tsan_iossim_dynamic.dylib`__tsan::cur_thread() + 11
frame #6: 0x000000010e9ea985 libclang_rt.tsan_iossim_dynamic.dylib`wrap_sysctlbyname + 37
frame #7: 0x00000001176bd390 libsystem_sim_kernel.dylib`assert_simulator_supported_host + 44
frame #8: 0x0000000116301a0c libSystem.B.dylib`libSystem_initializer + 56
frame #9: 0x000000010e928f14 dyld_sim`ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 518
frame #10: 0x000000010e929112 dyld_sim`ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 40
frame #11: 0x000000010e924547 dyld_sim`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 343
frame #12: 0x000000010e9244d3 dyld_sim`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 227
frame #13: 0x000000010e9244d3 dyld_sim`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 227
frame #14: 0x000000010e9244d3 dyld_sim`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 227
frame #15: 0x000000010e923704 dyld_sim`ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 134
frame #16: 0x000000010e923798 dyld_sim`ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 74
frame #17: 0x000000010e917342 dyld_sim`dyld::initializeMainExecutable() + 129
frame #18: 0x000000010e91b497 dyld_sim`dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 4395
frame #19: 0x000000010e916624 dyld_sim`start_sim + 136
frame #20: 0x000000011092879a dyld`dyld::useSimulatorDyld(int, macho_header const*, char const*, int, char const**, char const**, char const**, unsigned long*, unsigned long*) + 2308
frame #21: 0x0000000110926432 dyld`dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 837
frame #22: 0x0000000110921227 dyld`dyldbootstrap::start(dyld3::MachOLoaded const*, int, char const**, dyld3::MachOLoaded const*, unsigned long*) + 453
frame #23: 0x0000000110921025 dyld`_dyld_start + 37
I also tried changing Strip Style from All Symbols to Debugging Symbols but no avail. Any suggestion in this regard will be helpful. Thanks.
Which Xcode version are you using?
Because in Release Notes of Xcode 11.3.1 you can find a fix for the Thread Sanitizer.
Resolved an issue that prevented Xcode from launching processes with Thread Sanitizer enabled on macOS Catalina 10.15.2. (57822138)
I'm facing a really strange behavior in an iPad App. I create several bundles, the app downloads them an saves them to the documents directory.
I have a custom bundle manager where i can load the bundles like this.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *bundlePath;
if (![bundleName hasSuffix:#".bundle"]) {
bundlePath = [documentsDirectory stringByAppendingFormat:#"/%#.bundle", bundleName];
} else {
bundlePath = [documentsDirectory stringByAppendingFormat:#"/%#", bundleName];
}
NSBundle *bundle = nil;
NSError *error = nil;
bundle = [[NSBundle alloc] initWithPath:bundlePath];
if (!bundle) {
return nil;
}
[bundle loadAndReturnError:&error];
In debug mode all code works like a charm. The bundle gets loaded and the content can be used in the app. The bundles contain images and nibs, no code. In the bundle build settings I've set COMBINE_HIDPI_IMAGES to NO, so that the images will not be combined as tiff images. The bundles also do not contain any code.
So what's the problem. Well when starting the app without debugging (not connected to Xcode) the app crashes and generates this error message. [bundle loadAndReturnError:&error] is where the code crashes.
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 dyld 0x2fe8e2d8 strcmp + 0
1 dyld 0x2fe83aac ImageLoaderMachO::parseLoadCmds() + 56
2 dyld 0x2fe88d30 ImageLoaderMachOCompressed::instantiateFromFile(char const*, int, unsigned char const*, unsigned long long, unsigned long long, stat const&, unsigned int, unsigned int, linkedit_data_command const*, ImageLoader::LinkContext const&) + 296
3 dyld 0x2fe839c6 ImageLoaderMachO::instantiateFromFile(char const*, int, unsigned char const*, unsigned long long, unsigned long long, stat const&, ImageLoader::LinkContext const&) + 222
4 dyld 0x2fe7b0d4 dyld::loadPhase6(int, stat const&, char const*, dyld::LoadContext const&) + 664
5 dyld 0x2fe7e774 dyld::loadPhase5stat(char const*, dyld::LoadContext const&, stat*, int*, bool*, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 428
6 dyld 0x2fe7e498 dyld::loadPhase5(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 248
7 dyld 0x2fe7e37c dyld::loadPhase4(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 128
8 dyld 0x2fe7e29c dyld::loadPhase3(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 984
9 dyld 0x2fe7dc36 dyld::loadPhase1(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 110
10 dyld 0x2fe7ada4 dyld::loadPhase0(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 168
11 dyld 0x2fe7ab58 dyld::load(char const*, dyld::LoadContext const&) + 208
12 dyld 0x2fe7f8da dlopen + 802
13 libdyld.dylib 0x39dee946 dlopen + 46
14 CoreFoundation 0x31ab4910 _CFBundleDlfcnLoadBundle + 128
15 CoreFoundation 0x31ab478c _CFBundleLoadExecutableAndReturnError + 356
16 Foundation 0x323d2154 -[NSBundle loadAndReturnError:] + 844
17 Visitor Self Service 0x000e251a -[CoreBundleManager bundleForName:] (CoreBundleManager.m:70)
18 Visitor Self Service 0x000cd418 -[CoreProcessDefinition processBundle] (CoreProcessDefinition.m:226)
19 Visitor Self Service 0x000cf17e -[CoreProcessRuntime loadControllerForStep:] (CoreProcessRuntime.m:187)
20 Visitor Self Service 0x000ce9f4 -[CoreProcessRuntime performNextStepInProcessDefinition] (CoreProcessRuntime.m:112)
21 Visitor Self Service 0x000ba642 __62-[DynamicViewController prepareControllerForProcessDefinition]_block_invoke (DynamicViewController.m:107)
22 libdispatch.dylib 0x39ddb790 _dispatch_call_block_and_release + 8
23 libdispatch.dylib 0x39dde8be _dispatch_after_timer_callback + 10
24 libdispatch.dylib 0x39ddb5d8 _dispatch_client_callout + 20
25 libdispatch.dylib 0x39ddc48a _dispatch_source_invoke + 254
26 libdispatch.dylib 0x39ddee04 _dispatch_main_queue_callback_4CF + 164
27 CoreFoundation 0x31afb1ac __CFRunLoopRun + 1284
28 CoreFoundation 0x31a6e238 CFRunLoopRunSpecific + 352
29 CoreFoundation 0x31a6e0c4 CFRunLoopRunInMode + 100
30 GraphicsServices 0x35629336 GSEventRunModal + 70
31 UIKit 0x3398a2b4 UIApplicationMain + 1116
32 Visitor Self Service 0x000b66d8 main (main.m:16)
33 libdyld.dylib 0x39deeb1c start + 0
Finally I got it working.
There are several steps for setting up a proper bundle.
In the Project Build Settings for the Bundle set
Architectures => armv7, armv7s
Supported Plattforms => iOS
Valid Architectures => armv7, armv7s
Set up a valid Code Sign Identity
Set up a matching provisioning profile
You also need a Info.plist
Required Device Capabilities => armv7, armv7s
Principal Class => Your bundles principal class name
Executable File => Same as Principal Class
Note
External code execution is prohibited by the Apple Review Guidelines, so it's only possible in In-House Apps.
2.7 Apps that download code in any way or form will be rejected
2.8 Apps that install or launch other executable code will be rejected
I tested my app in Instruments. No leaks found, but app crashes (not immediately - after ~20 minutes [depends on user's activity] of working). I viewed Allocations. It reports:
Category | Live Bytes | Count Live | # Living | # Transitory | Overall Bytes | # Allocations (Net / Overall)
Malloc 16 Bytes | 235088 | 14693 | 0 | 235088 | 14693 | 1.00
All records (when I view detailed info for "Malloc 16 Bytes") are made for only one object:
# | Object Address | Category | Creation Time | Live | Size | Responsible Library | Responsible Caller
0 | 0x104b50 | 817461248 | • | dyld | _dyld_start
(...and 14693 records with same fields data, except, of course, #).
Stack Trace:
0 CoreFoundation __CFAllocatorSystemAllocate
1 CoreFoundation CFAllocatorAllocate
2 CoreFoundation __CFGetConverter
3 CoreFoundation CFStringEncodingGetConverter
4 CoreFoundation CFStringGetSystemEncoding
5 CoreFoundation __CFStringInitializeSystemEncoding
6 CoreFoundation __CFInitialize
7 dyld ImageLoaderMachO::doImageInit(ImageLoader::LinkContext const&)
8 dyld ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&)
9 dyld ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&)
10 dyld ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&)
11 dyld ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&)
12 dyld dyld::initializeMainExecutable()
13 dyld dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**)
14 dyld dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*)
15 dyld _dyld_start
I can't paste all code here (app is not a few lines). But, please, give me some advice - where to search for memory leak or smth. else...
IMHO, your number one priority is to let your application run. Try to locate where the problem is, by commenting part of your code; if the app doesn't crash anymore, then the problem is located within the part you just commented, if it still crashes, then it must be somewhere else. Repeat the steps until you fix the bug.
After you get your app run, then you can start to find its leak or improve performance.
I retrieved the crash reports from iTunes Connect.
I referenced this site.
http://webcache.googleusercontent.com/search?q=cache:MmxwdXObZLMJ:www.anoshkin.net/blog/2008/09/09/iphone-crash-logs/+iphone+crash+debig&cd=2&hl=en&ct=clnk
I tried....
$ symbolicatecrash report.crash MobileLines.app.dSYM > report-with-symbols.crash
Error in symbol file for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.2 (7D11)/Symbols/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit<br><br>
Error in symbol file for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.2 (7D11)/Symbols/System/Library/PrivateFrameworks/WebCore.framework/WebCore<br><br>
Error in symbol file for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.2 (7D11)/Symbols/System/Library/Frameworks/Foundation.framework/Foundation<br><br>
Error in symbol file for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.2 (7D11)/Symbols/usr/lib/libSystem.B.dylib<br><br>
Error in symbol file for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.2 (7D11)/Symbols/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices<br><br>
Error in symbol file for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.2 (7D11)/Symbols/System/Library/Frameworks/UIKit.framework/UIKit<br><br>
Error in symbol file for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.2 (7D11)/Symbols/System/Library/Frameworks/OpenGLES.framework/MBXGLEngine.bundle/MBXGLEngine<br><br>
Error in symbol file for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.2 (7D11)/Symbols/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox<br><br>
Error in symbol file for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.2 (7D11)/Symbols/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
BUT... I didn't result. (find error message)
* This directory is located "bulid/Distribution-iphones"
* "MYGAME.app" file and "MYGAME.app.dSYM" file is located in same directory.
How can i do solve this problem. ?
Please help me :)
* Crash log (carsh at thread 2 )
-----------------------------------------------------------
Incident Identifier: 95230C2E-CD83-46BF-8DAE-F38BCD46B910<br>
Process: MYGAMELite [303]<br>
Path: /var/mobile/Applications/4FB79BEC-2BF0-438B-82A8-C302CD52A85C/MYGAMELite.app/MYGAMELite<br>
Identifier: MYGAMELite<br>
Version: ??? (???)<br>
Code Type: ARM (Native)<br>
Parent Process: launchd [1]<br><br>
Date/Time: 2010-06-03 11:43:52.875 +0800<br>
OS Version: iPhone OS 3.1.2 (7D11)<br>
Report Version: 104<br><br>
Exception Type: EXC_BAD_ACCESS (SIGSEGV)<br>
Exception Codes: KERN_INVALID_ADDRESS at 0x03e3a002<br>
Crashed Thread: 2<br><br>
Thread 2 Crashed:<br>
0 AudioToolbox 0x330d708c AU3DMixerEmbedded::SumInput16(unsigned long, AudioBufferList const&, AudioBufferList const&, unsigned long, float, unsigned long)
<br>1 AudioToolbox 0x330d89a0 AU3DMixerEmbedded::Render(unsigned long&, AudioTimeStamp const&, unsigned long)
<br>2 AudioToolbox 0x32fe6bb8 AUBase::DoRender(unsigned long&, AudioTimeStamp const&, unsigned long, unsigned long, AudioBufferList&)
<br>3 AudioToolbox 0x32fe6504 Render
<br>4 AudioToolbox 0x330160b8 AUInputElement::PullInput(unsigned long&, AudioTimeStamp const&, unsigned long, unsigned long)
<br>5 AudioToolbox 0x33023fa8 AUInputFormatConverter2::InputProc(OpaqueAudioConverter*, unsigned long*, AudioBufferList*, AudioStreamPacketDescription**, void*)
<br>6 AudioToolbox 0x32fe4b60 AudioConverterChain::CallInputProc(unsigned long)
<br>7 AudioToolbox 0x32fe4a5c AudioConverterChain::FillBufferFromInputProc(unsigned long*, CABufferList*)
<br>8 AudioToolbox 0x32fe4790 BufferedAudioConverter::GetInputBytes(unsigned long, unsigned long&, CABufferList const*&)
<br>9 AudioToolbox 0x33023e30 CBRConverter::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*)
<br>10 AudioToolbox 0x32fe4284 BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*)
<br>11 AudioToolbox 0x32fe44a4 AudioConverterChain::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*)
<br>12 AudioToolbox 0x32fe4284 BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*)
<br>13 AudioToolbox 0x32fe3f10 AudioConverterFillComplexBuffer
<br>14 AudioToolbox 0x33023844 AUConverterBase::RenderBus(unsigned long&, AudioTimeStamp const&, unsigned long, unsigned long)
<br>15 AudioToolbox 0x330ce928 AURemoteIO::RenderBus(unsigned long&, AudioTimeStamp const&, unsigned long, unsigned long)
<br>16 AudioToolbox 0x32fe6bb8 AUBase::DoRender(unsigned long&, AudioTimeStamp const&, unsigned long, unsigned long, AudioBufferList&)
<br>17 AudioToolbox 0x330cf308 AURemoteIO::PerformIO(int, unsigned int, unsigned int, AQTimeStamp const&, AQTimeStamp const&)
<br>18 AudioToolbox 0x330cf4cc AURIOCallbackReceiver_PerformIOSync
<br>19 AudioToolbox 0x330c76fc _XPerformIOSync
<br>20 AudioToolbox 0x330181d8 mshMIGPerform
<br>21 AudioToolbox 0x3309cec8 MSHMIGDispatchMessage
<br>22 AudioToolbox 0x330d48d4 AURemoteIO::IOThread::Entry(void*)
<br>23 AudioToolbox 0x32fc9f20 CAPThread::Entry(CAPThread*)
<br>24 libSystem.B.dylib 0x30b5b7b0 _pthread_body
---------------------------------------------------------------------------------
There's no need to do symbolication, as the crash log has been symbolicated. "Symbolication" just turns all numerical addresses into meaningful function names.
In your case, it seems the audio file is messed up.
I am getting leak and I cannot detect from where this is happening. The stack trace does not give full info after dyld open. For few leaks I am not getting any stack trace info. All I get is only object memory address. Is anyone else facing the same issue. I am using XCode 3.2 on show leopard.
18 0x103038
17 0x1033c7
16 0x1034a1
15 0x90145f48
14 dyld dlopen
13 dyld dyld::link(ImageLoader*, bool, ImageLoader::RPathChain const&)
12 dyld ImageLoader::link(ImageLoader::LinkContext const&, bool, bool, ImageLoader::RPathChain const&)
11 dyld ImageLoader::recursiveLoadLibraries(ImageLoader::LinkContext const&, bool, ImageLoader::RPathChain const&)
10 dyld dyld::libraryLocator(char const*, bool, char const*, ImageLoader::RPathChain const*)
9 dyld dyld::load(char const*, dyld::LoadContext const&)
8 dyld dyld::loadPhase0(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*)
7 dyld dyld::loadPhase1(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*)
6 dyld dyld::loadPhase3(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*)
5 dyld dyld::loadPhase4(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*)
4 dyld dyld::loadPhase5(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*)
3 dyld dyld::mkstringf(char const*, ...)
2 dyld strdup
1 dyld mallocenter
I'm seeing very similar behavior in xcode 3.2. The dyld leak, that didn't appear in xcode 3.1.x, and I'm not seeing anything other than a memory address for any other leaks. Just to prove I wasn't crazy, I instantiated several UILabels using alloc and didn't release them. Sure enough, xcode shows UILabel leaks, but the stacktrace is only memory addresses. In 3.1.x I used to see a stack that was much more meaningful, complete with class names. Is this a bug in the new xcode?