gpt4 book ai didi

objective-c - EXC_BAD_ACCESS 信号

转载 作者:行者123 更新时间:2023-12-03 16:59:31 25 4
gpt4 key购买 nike

我有一个方法启动,它连接到IB中的一个按钮,基本上,第一次运行它时,一切正常,但是当我第二次运行它时(我向你保证数据不会发生任何其他变化)之间),在第一个循环(int i)之后我得到一个 EXC_BAD_ACCESS 。我打开了 NSZombieEnabled,它没有告诉我任何信息,我只是简单地得到一个简单的

Program received signal: “EXC_BAD_ACCESS”. sharedlibrary apply-load-rules all

方法如下:

- (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);
}
}
}

}

我用 NSLogged 来查看是否可以找到一些东西,这是该方法第二次被调用时的控制台:

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)

最佳答案

您的最终 NSLog(错误)很可能是您粘贴的输出中崩溃的内容。 executeAndReturn:errorInfo 参数的文档说:

On return, if an error occurs, a pointer to an error information dictionary.

(强调已添加)。因此,如果没有错误,则无法保证未初始化的 error 变量不是垃圾指针。

关于objective-c - EXC_BAD_ACCESS 信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5523333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com