Objective c EXC\u坏访问信号
我有一个方法start,它连接到IB中的一个按钮,基本上,第一次运行它时,一切正常,但当我第二次运行它时(我向您保证,中间的数据不会发生任何其他情况),在第一次循环(int I)后,我会得到一个EXC_BAD_访问。我打开了NSZombieEnabled,它没有告诉我任何事情,我只是简单地得到了一个简单的答案 程序接收信号: “EXC_坏访问”。共享图书馆 应用所有加载规则 方法如下:Objective c EXC\u坏访问信号,objective-c,cocoa,memory-management,nsarray,exc-bad-access,Objective C,Cocoa,Memory Management,Nsarray,Exc Bad Access,我有一个方法start,它连接到IB中的一个按钮,基本上,第一次运行它时,一切正常,但当我第二次运行它时(我向您保证,中间的数据不会发生任何其他情况),在第一次循环(int I)后,我会得到一个EXC_BAD_访问。我打开了NSZombieEnabled,它没有告诉我任何事情,我只是简单地得到了一个简单的答案 程序接收信号: “EXC_坏访问”。共享图书馆 应用所有加载规则 方法如下: - (IBAction)start:(id)sender { NSLog(@"1"); NS
- (IBAction)start:(id)sender {
NSLog(@"1");
NSArray* firstArr = [data objectAtIndex:0];
NSLog(@"2");
for (int i=1; i < [data count]; i++) {
NSLog(@"%@", data);
NSArray* currArray = [data objectAtIndex:i];
NSString* fileName = [currArray objectAtIndex:[firstArr indexOfObject:@"UseFile"]];
NSString* filePath = [NSString stringWithFormat:@"/%@", fileName];
NSString* saveAs = [currArray objectAtIndex:[firstArr indexOfObject:@"SaveFileAs"]];
NSLog(@"3");
for (int j=0; j < [firstArr count]; j++) {
NSLog(@"4");
if ([self isIndexIdentifier:j]) {
NSLog(@"5");
NSString* searchStr = [firstArr objectAtIndex:j];
NSString* replaceStr = [currArray objectAtIndex:j];
NSDictionary* error;
NSLog(@"6");
NSString* appleScript = [NSString stringWithFormat:
@"set searchstring to \"%@\"\n"
@"set replacestring to \"%@\"\n"
@"tell application \"QuarkXPress\"\n"
@"activate\n"
@"if (not (exists document \"%@\")) then\n"
@"open POSIX file \"%@\" with Suppress All Warnings\n"
@"end if\n"
@"tell document \"%@\"\n"
@"repeat with tb from 1 to count of text box\n"
@"tell text box tb\n"
@"set (every text where it is searchstring) to replacestring\n"
@"end tell\n"
@"end repeat\n"
@"end tell\n"
@"end tell\n",
searchStr, replaceStr, fileName, filePath, fileName];
NSLog(@"7");
NSLog(@"%@", appleScript);
NSLog(@"8");
NSAppleScript *script = [[NSAppleScript alloc] initWithSource: appleScript];
NSLog(@"9");
[script executeAndReturnError:&error];
NSLog(@"10");
[script release];
NSLog(@"11");
NSLog(@"%@", error);
}
}
}
您是否尝试过使用僵尸工具运行应用程序?
您的问题很可能是数据的过度发布,仪器应该会发现这一点。
如果弹出“检测到僵尸”消息,请单击内存地址并显示扩展详细信息面板。(视图→ 扩展详细信息)您的最终NSLog(of
error
)很可能就是您粘贴的输出崩溃的原因。executeAndReturn:
的errorInfo
参数的文档说明:
返回时,如果发生错误,则返回指向错误信息字典的指针
(重点补充)。因此,如果没有错误,就不能保证未初始化的
error
变量不是垃圾指针。谢谢你们,这就是问题所在!我把它注释掉了,它没有崩溃,但是我怎么知道当时是否发生了错误呢?我尝试了if(error!=nil)nslog。。。。但它崩溃了。创建错误时是否必须将其设置为零?它不是自动为零吗?如果它不是零,那么它设置为什么?无论如何,再次感谢你。当你创建它的时候,你应该把它设置为零。它不是自动为零;这只适用于成员变量,而不是局部变量。未初始化的变量被设置为该内存中的任意随机值,这就是为什么在不同的运行中会得到不同的结果。@user635064:通常应该先检查传递错误指针的函数的返回值,只有当该返回指示发生错误时,您才应该尝试使用错误指针。问题是user635064已经尝试了NSZombieEnabled
,它也做了同样的事情,只是没有所有好的工具进行进一步的调查。如果问题是发送给解除分配对象的消息,则任何一个都可以证明这一点。
run
2011-04-02 08:55:38.145 TestUI[4472:a0f] 1
2011-04-02 08:55:38.145 TestUI[4472:a0f] 2
2011-04-02 08:55:38.146 TestUI[4472:a0f] (
(
UseFile,
xxxxxxxxxxxxx,
SaveFileAs
),
(
"1.qxp",
11111,
""
),
(
"2.qxp",
aslkvknv,
""
),
(
"3.qxp",
ABCDEFG,
""
),
(
"4.qxp",
222222222,
""
),
(
"5.qxp",
asdf,
adsffdsa
)
)
2011-04-02 08:55:38.146 TestUI[4472:a0f] 3
2011-04-02 08:55:38.147 TestUI[4472:a0f] 4
2011-04-02 08:55:38.147 TestUI[4472:a0f] 4
2011-04-02 08:55:38.147 TestUI[4472:a0f] 5
2011-04-02 08:55:38.147 TestUI[4472:a0f] 6
2011-04-02 08:55:38.148 TestUI[4472:a0f] 7
2011-04-02 08:55:38.148 TestUI[4472:a0f] set searchstring to "xxxxxxxxxxxxx"
set replacestring to "11111"
tell application "QuarkXPress"
activate
if (not (exists document "1.qxp")) then
open POSIX file "/1.qxp" with Suppress All Warnings
end if
tell document "1.qxp"
repeat with tb from 1 to count of text box
tell text box tb
set (every text where it is searchstring) to replacestring
end tell
end repeat
end tell
end tell
2011-04-02 08:55:38.148 TestUI[4472:a0f] 8
2011-04-02 08:55:38.148 TestUI[4472:a0f] 9
2011-04-02 08:55:38.517 TestUI[4472:a0f] 10
2011-04-02 08:55:38.517 TestUI[4472:a0f] 11
Program received signal: “EXC_BAD_ACCESS”.
sharedlibrary apply-load-rules all
(gdb)