iOS的访问不可能找到 [英] iOS bad access impossible to find

查看:94
本文介绍了iOS的访问不可能找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于这么多小时,我被困在一个愚蠢的不好的访问。我完全无法找到它。
我希望你们中的一些人能够把答案告诉我。
在下面的代码中,它出现在行: NSString * stringCallVisit = [[NSString alloc] initWithFormat:.....
我可以'



如果我注释的方法 NSString * stringCallVisit = [[NSString alloc ] initWithFormat:... 不会出现即使我 id obj = callVisit.injectionby; 所以我认为坏的访问不是从callVisit对象,而是从stringCallVisit对象。



感谢您的帮助,

   - (NSString *)getCallVisitForIntervention:(Intervention *)theIntervention 
{

NSManagedObjectContext * context = [iPad_TestAppDelegate mainContext];
NSError * error;

NSFetchRequest * requestCallVisit = [[NSFetchRequest alloc] init];
[requestCallVisit setEntity:[NSEntityDescription entityForName:@CallVisitinManagedObjectContext:context]];

NSPredicate * predicateInterventionID = [NSPredicate predicateWithFormat:@intervention_id =%@,theIntervention.id];
[requestCallVisit setPredicate:predicateInterventionID];

NSMutableArray * callVisits = [[context executeFetchRequest:requestCallVisit error:& error] mutableCopy];



NSString * xml = @< CallVisits>;

for(CallVisit * callVisit in callVisits)
{

NSString * stringCallVisit = [[NSString alloc] initWithFormat:
@< CallVisit> 。
< id>%@< / id>
< injectionby>%@< / injectionby>
< injectionspot>%@< / injectionspot>
< intervention_id>%@< / intervention_id>
< fls>%d< / fls>
< weight>%d< / weight>
< height>%d< / height>
< painAtInjection>%d< / painAtInjection>
< created>%@< / created>
< siteReaction>%d< / siteReaction>
< technicalComplain>%d< / technicalComplain>
< field1>%d< / field1>
< field2>%d< / field2>
< riskCompliance>%d< / riskCompliance>
< reasoncompliance>%@< / reasonCompliance>
< placebo>%@< / placebo>
< needlereceived>%@< / needlereceived>
< compliance>%d< / compliance>
< psychologicalCondition>%d< / psychologicalCondition>
< keepsegment>%d< / keepsegment>
< / CallVisit>,
callVisit.id,
callVisit.injectionby,
callVisit.injectionspot,
callVisit.intervention_id,
[callVisit .fls doubleValue],
[callVisit.weight doubleValue],
[callVisit.height doubleValue],
[callVisit.painAtInjection intValue],
callVisit.created,
[callVisit.site1 intValue],
[callVisit.field2 intValue],
[callVisit.riskComplain intValue],
[ ,
callVisit.reasonCompliance,
callVisit.placebo,
callVisit.needlereceived,
[callVisit.compliance intValue],
[callVisit.psychologicalCondition intValue],
[callVisit.keepsegment intValue]];



xml = [xml stringByAppendingString:stringCallVisit];
[stringCallVisit release];

id obj = callVisit;

}
[callVisits release];
[requestCallVisit release];

xml = [xml stringByAppendingString:@< / CallVisits>];

return xml;
}

EDIT: b

我做了你说的,但我无法理解日志,我没有收到一个地址到信息malloc。
我有点失落:)



EDIT
这是日志。但它,奇怪,但知道应用程序崩溃在另一个地方。

  GuardMalloc [iPad Test-7405]:VM无法分配397648字节
GuardMalloc [iPad Test-7405]:显式陷入调试器!
sharedlibrary apply-load-rules all
重新设置断点1时出错:
Catchpoint 2(throw)iPad Test(7405,0xaccab2c0)malloc:使用标准记录器将malloc堆栈记录到磁盘
GuardMalloc [iPad Test-7405]:*** mmap(size = 2097152)失败(错误代码= 12)
***错误:无法分配区域
*** set a断点在malloc_error_break中调试
GuardMalloc [iPad Test-7405]:*** mmap(size = 2097152)失败(错误代码= 12)
***错误:无法分配区域
***在malloc_error_break中设置断点以调试
没有可用于编程的内存:调用malloc失败
重新设置断点1时出错:
重新设置断点1时出错:
GuardMalloc [iPad Test-7405]:*** mmap(size = 2097152)失败(错误代码= 12)
***错误:无法分配区域
*** set a断点在malloc_error_break到debug
当前语言:auto;目前是objective-c
GuardMalloc [iPad Test-7405]:*** mmap(size = 2097152)失败(错误代码= 12)
***错误:无法分配区域
***设置一个断点在malloc_error_break到调试
没有内存可用于编程:调用malloc失败
GuardMalloc [iPad Test-7405]:*** mmap(size = 2097152)失败(错误代码= 12)
***错误:无法分配区域
***在malloc_error_break中设置断点以调试
没有可用于编程的内存:调用malloc失败
GuardMalloc [ iPad Test-7405]:*** mmap(size = 2097152)失败(错误代码= 12)
***错误:无法分配区域
***设置一个断点在malloc_error_break调试
没有可用于编程的内存:调用malloc失败
(gdb)


解决方案

请注意,weight,height和fls都是双精度值,但是您使用的是%d(整数)占位符。你将在该xml中获得有趣的值。 - magma 45分钟前



我确认只需将%d替换为%.2f即可解决问题!非常感谢您的帮助和您的时间!特别是他的眼睛的岩浆:) -


I'm stuck with a stupid bad access since so many hours. I'm totally unable to find it. I hope some of you will be able to show me the answer into the light. In the code bellow it appear on the line : NSString * stringCallVisit = [[NSString alloc]initWithFormat:..... I can't understand, all the objects are local of the method except the parameter theIntervention.

if i comment the method NSString * stringCallVisit = [[NSString alloc]initWithFormat:... the bad access don't appear even if i do id obj = callVisit.injectionby; instead of; So i suppose that the bad access is not from the callVisit object but certainly from the stringCallVisit object. But why i'm just instantiate it on the tine where the bad access appear.

Thanks for your help,

-(NSString*)getCallVisitForIntervention:(Intervention*)theIntervention
{

NSManagedObjectContext *context = [iPad_TestAppDelegate mainContext];
NSError *error;

NSFetchRequest *requestCallVisit = [[NSFetchRequest alloc]init];
[requestCallVisit setEntity:[NSEntityDescription entityForName:@"CallVisit" inManagedObjectContext:context]];

NSPredicate *predicateInterventionID = [NSPredicate predicateWithFormat:@"intervention_id = %@",theIntervention.id];
[requestCallVisit setPredicate:predicateInterventionID];        

NSMutableArray *callVisits = [[context executeFetchRequest:requestCallVisit error:&error]mutableCopy];



NSString *xml  = @"<CallVisits>";

for(CallVisit *callVisit in callVisits) 
{

    NSString * stringCallVisit = [[NSString alloc]initWithFormat:
                                  @"<CallVisit>"
                                  "<id>%@</id>"
                                  "<injectionby>%@</injectionby>"
                                  "<injectionspot>%@</injectionspot>"
                                  "<intervention_id>%@</intervention_id>"
                                  "<fls>%d</fls>"
                                  "<weight>%d</weight>"
                                  "<height>%d</height>"
                                  "<painAtInjection>%d</painAtInjection>"
                                  "<created>%@</created>"
                                  "<siteReaction>%d</siteReaction>"
                                  "<technicalComplain>%d</technicalComplain>"
                                  "<field1>%d</field1>"
                                  "<field2>%d</field2>"
                                  "<riskCompliance>%d</riskCompliance>"
                                  "<reasonCompliance>%@</reasonCompliance>"
                                  "<placebo>%@</placebo>"
                                  "<needlereceived>%@</needlereceived>"
                                  "<compliance>%d</compliance>"
                                  "<psychologicalCondition>%d</psychologicalCondition>"
                                  "<keepsegment>%d</keepsegment>"
                                  "</CallVisit>",
                                  callVisit.id,
                                  callVisit.injectionby,
                                  callVisit.injectionspot,
                                  callVisit.intervention_id,
                                  [callVisit.fls doubleValue],
                                  [callVisit.weight doubleValue],
                                  [callVisit.height doubleValue],
                                  [callVisit.painAtInjection intValue],
                                  callVisit.created,
                                  [callVisit.siteReaction intValue],
                                  [callVisit.technicalComplain intValue],
                                  [callVisit.field1 intValue],
                                  [callVisit.field2 intValue],
                                  [callVisit.riskCompliance intValue],
                                  callVisit.reasonCompliance,
                                  callVisit.placebo,
                                  callVisit.needlereceived,
                                  [callVisit.compliance intValue],
                                  [callVisit.psychologicalCondition intValue],
                                  [callVisit.keepsegment intValue]];



    xml = [xml stringByAppendingString:stringCallVisit];
    [stringCallVisit release];

    id obj = callVisit;

}       
[callVisits release];
[requestCallVisit release];

xml = [xml stringByAppendingString:@"</CallVisits>"];

return xml;
}

EDIT:

I did what you said but i'mm unable to understand the log and i don't received an adress to to the info malloc. I'm a bit lost :)

EDIT Here is the log. But it,s strange but know the app crash at an other place.

GuardMalloc[iPad Test-7405]: Failed to VM allocate 397648 bytes
GuardMalloc[iPad Test-7405]: Explicitly trapping into debugger!!!
sharedlibrary apply-load-rules all
Error in re-setting breakpoint 1:
Catchpoint 2 (throw)iPad Test(7405,0xaccab2c0) malloc: recording malloc stacks to disk using standard recorder
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
Error in re-setting breakpoint 1:
Error in re-setting breakpoint 1:
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Current language:  auto; currently objective-c
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
(gdb) 

解决方案

note that weight, height and fls are double values, and yet you're using a %d (integer) placeholder for them. you're going to get funny values in that xml. – magma 45 mins ago

I confirm Just replace %d by %.2f solve the problem ! Big thanks all for your help and your time ! And specially magma for his eyes :) –

这篇关于iOS的访问不可能找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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