NSLog上的EXC_BAD_ACCESS没有字符串格式 [英] EXC_BAD_ACCESS on NSLog with no string formatting

查看:335
本文介绍了NSLog上的EXC_BAD_ACCESS没有字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面一行代码中得到一个EXC_BAD_ACCESS(或malloc错误):

I'm getting an EXC_BAD_ACCESS (or a malloc error) on the following line of code:

NSLog(@"Points:");  

这对我来说没有意义,因为它应该访问字符串常量。它通常是一个EXC_BAD_ACCESS,但它偶尔是以下错误(在同一行):

Which makes zero sense to me, as it should be accessing a string constant and nothing else. It's usually an EXC_BAD_ACCESS, but it occasionally is the following error (on the same line):

Annotate23D(50572,0xac6bb2c0) malloc: *** error for object 0x7051004: incorrect checksum for freed object - object was probably modified after being freed.  

malloc错误的堆栈跟踪(我很难得到一个完整的错误的访问错误)是:

The stack trace for the malloc error (I'm having a hard time getting a full one out of the bad access error) is:

#0  0x960e7c97 in malloc_error_break ()
#1  0x960a94ce in szone_error ()
#2  0x960a954e in free_list_checksum_botch ()
#3  0x960afec0 in small_malloc_from_free_list ()
#4  0x960b124c in szone_malloc_should_clear ()
#5  0x960b166b in szone_malloc ()
#6  0x960e7962 in malloc_zone_malloc ()
#7  0x960e8882 in malloc ()
#8  0x020e5837 in uhash_hashUChars ()
#9  0x020e5c01 in uhash_setResizePolicy ()
#10 0x020e5ca5 in uhash_init ()
#11 0x02075896 in uhash_open ()
#12 0x021f5978 in icu::ZoneMeta::getCanonicalCLDRID ()
#13 0x021f6a4f in icu::ZoneMeta::getCanonicalCLDRID ()
#14 0x021ab551 in icu::TimeZone::getCanonicalID ()
#15 0x021bfaf2 in ucal_getCanonicalTimeZoneID ()
#16 0x024d8bf4 in __nameStringOK ()
#17 0x024d8ae4 in -[__NSPlaceholderTimeZone __initWithName:cache:] ()
#18 0x024d89d0 in -[__NSPlaceholderTimeZone initWithName:] ()
#19 0x024d884b in +[NSTimeZone timeZoneWithName:] ()
#20 0x024d8768 in +[NSTimeZone systemTimeZone] ()
#21 0x024d84d7 in +[NSTimeZone defaultTimeZone] ()
#22 0x024d846d in CFTimeZoneCopyDefault ()
#23 0x024e6726 in CFCalendarCreateWithIdentifier ()
#24 0x02509e67 in __CFLogCString ()
#25 0x02509db3 in _CFLogvEx ()
#26 0x00b99b63 in NSLogv ()
#27 0x00b99ad5 in NSLog ()
#28 0x00008323 in -[Cylinderoid generateMesh] (self=0x6a73fa0, _cmd=0x6e836) at /Users/haldean/Code/ipad/Annotate23D/Annotate23D/Cylinderoid.mm:154
#29 0x0006cd85 in -[MeshGenerator rendererForObjects:] (self=0x6a67b80, _cmd=0x6e246, workspace=0xa83f270) at /Users/haldean/Code/ipad/Annotate23D/Annotate23D/MeshGenerator.m:16
#30 0x00005367 in -[WorkspaceViewController renderButton:] (self=0xa8377f0, _cmd=0x6e4ac, sender=0x6a58260) at /Users/haldean/Code/ipad/Annotate23D/Annotate23D/WorkspaceViewController.m:304
#31 0x02562ec9 in -[NSObject performSelector:withObject:withObject:] ()
#32 0x002365c2 in -[UIApplication sendAction:to:from:forEvent:] ()
#33 0x0023655a in -[UIApplication sendAction:toTarget:fromSender:forEvent:] ()
#34 0x002dbb76 in -[UIControl sendAction:to:forEvent:] ()
#35 0x002dc03f in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
#36 0x002db2fe in -[UIControl touchesEnded:withEvent:] ()
#37 0x004f4a2a in _UIGestureRecognizerUpdate ()
#38 0x025359ce in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#39 0x024cc670 in __CFRunLoopDoObservers ()
#40 0x024984f6 in __CFRunLoopRun ()
#41 0x02497db4 in CFRunLoopRunSpecific ()
#42 0x02497ccb in CFRunLoopRunInMode ()
#43 0x0244a879 in GSEventRunModal ()
#44 0x0244a93e in GSEventRun ()
#45 0x00233a9b in UIApplicationMain ()
#46 0x00002b88 in main (argc=1, argv=0xbffff590) at /Users/haldean/Code/ipad/Annotate23D/Annotate23D/main.m:1  

可能相关的文件是有问题的是一个Objective-C ++文件与ARC打开。该方法本身是巨大的,所以我把它在这里,以保持问题简短。有问题的行是行94.任何想法如何解决它或如何调试非常感谢。提前致谢!

It may be relevant that the file in question is an Objective-C++ file with ARC turned on. The method itself is huge, so I put it up here to keep the question shortish. The line in question is line 94. Any ideas on either how to fix it or how to debug are greatly appreciated. Thanks in advance!

我现在也遇到页面损坏错误。从调试器:

I'm now also getting page corruption errors. From the debugger:

Annotate23D(50697) malloc: protecting edges
Annotate23D(50697) malloc: recording malloc stacks to disk using standard recorder
Annotate23D(50697) malloc: process 50678 no longer exists, stack logs deleted from /tmp/stack-logs.50678.Annotate23D.QDMh8a.index
Annotate23D(50697) malloc: stack logs being written into /tmp/stack-logs.50697.Annotate23D.XuPnEH.index
objc[50697]: autorelease pool page 0x7239000 corrupted
  magic 0 3f473a55 3f20c2f1 0
  pthread 0x43af3ce7

(gdb) bt
#0  0x026f28e5 in _objc_trap ()
#1  0x026f296e in _objc_fatal ()
#2  0x02706960 in objc_autoreleasePoolPush ()
#3  0x0248a95a in _CFAutoreleasePoolPush ()
#4  0x00b24e2b in NSPushAutoreleasePool ()
#5  0x00b99af4 in NSLogv ()
#6  0x00b99ad5 in NSLog ()
#7  0x00008323 in -[Cylinderoid generateMesh] (self=0x6ddd8a0, _cmd=0x6e836) at /Users/haldean/Code/ipad/Annotate23D/Annotate23D/Cylinderoid.mm:151
#8  0x0006cd85 in -[MeshGenerator rendererForObjects:] (self=0x6a9de30, _cmd=0x6e246, workspace=0x6dc1460) at /Users/haldean/Code/ipad/Annotate23D/Annotate23D/MeshGenerator.m:16
#9  0x00005367 in -[WorkspaceViewController renderButton:] (self=0x6db8a30, _cmd=0x6e4ac, sender=0x6dbd6a0) at /Users/haldean/Code/ipad/Annotate23D/Annotate23D/WorkspaceViewController.m:304
#10 0x02562ec9 in -[NSObject performSelector:withObject:withObject:] ()
#11 0x002365c2 in -[UIApplication sendAction:to:from:forEvent:] ()
#12 0x0023655a in -[UIApplication sendAction:toTarget:fromSender:forEvent:] ()
#13 0x002dbb76 in -[UIControl sendAction:to:forEvent:] ()
#14 0x002dc03f in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
#15 0x002db2fe in -[UIControl touchesEnded:withEvent:] ()
#16 0x004f4a2a in _UIGestureRecognizerUpdate ()
#17 0x025359ce in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#18 0x024cc670 in __CFRunLoopDoObservers ()
#19 0x024984f6 in __CFRunLoopRun ()
#20 0x02497db4 in CFRunLoopRunSpecific ()
#21 0x02497ccb in CFRunLoopRunInMode ()
#22 0x0244a879 in GSEventRunModal ()
#23 0x0244a93e in GSEventRun ()
#24 0x00233a9b in UIApplicationMain ()
#25 0x00002b88 in main (argc=1, argv=0xbffff590) at /Users/haldean/Code/ipad/Annotate23D/Annotate23D/main.m:16
(gdb) info malloc-history 0x7239000
Alloc: Block address: 0x07239000 length: 4096
Stack - pthread: 0xac6bb2c0 number of frames: 4
    0: 0x960e76ee in malloc_zone_memalign
    1: 0x270697d in objc_autoreleasePoolPush
    2: 0x2b22 in main at /Users/haldean/Code/ipad/Annotate23D/Annotate23D/main.m:16
    3: 0x2ae5 in start


推荐答案

在我建议的评论中:


问题不在于 NSLog 。问题可能是一些内存被砸了,这导致在 NSLog 崩溃。它可能会帮助,如果你可以分解你使用的方法,使其更容易阅读,甚至将功能分离成一个新的对象。此外,避免使用魔法数字(3& 6)。

The problem is not with NSLog. The problem is probably that some memory is getting smashed and that is causing the crash in NSLog. It would probably help if you could break down that method you're using to make it easier to read, perhaps even separating the functionality into a new object. Also, avoid the use of magic numbers (3 & 6).

看来@haldean使用这个建议,问题。我不能因为实际上正在努力追踪问题的努力而声称信誉,但我很高兴建议得到帮助。

It appears that @haldean went with this suggestion and tracked down the problem. I can't claim credit for actually doing the hard work of tracking down the problem, but I'm happy the suggestion helped.

这篇关于NSLog上的EXC_BAD_ACCESS没有字符串格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆