gpt4 book ai didi

ios - MIDINetworkConnection EXC_BAD_ACCESS 错误

转载 作者:行者123 更新时间:2023-11-29 10:34:31 25 4
gpt4 key购买 nike

我正在开发一个控制 daw 软件的应用程序。有时我会收到 EXC_BAD_ACCESS 错误。我相信它与 MIDINetworkConnection 有关,即使该项目启用了 ARC。它似乎试图访问连接数,但访问了错误的内存地址。任何人都可以发现问题吗?

- (NSString*) describeConnections {

NSMutableArray* connections = [NSMutableArray arrayWithCapacity:[[[MIDINetworkSession defaultSession] connections] count]];
for (MIDINetworkConnection* connection in [[MIDINetworkSession defaultSession] connections]) {
[connections addObject:[[connection host] name]];
}
if ([connections count] > 0) {
return [connections componentsJoinedByString:@", "];
}
else{
return @"(Not connected)";

}

}

断点错误停止于

 NSMutableArray* connections = [NSMutableArray arrayWithCapacity:[[[MIDINetworkSession     defaultSession] connections] count]];

消息:Thread 1: EXC_BAD_ACCESS(code=1, address=0x2033b00c)

在调试器中,我看到 connections = (NSMutableArray*)0x839ab1e0 与上述错误不匹配。这可能是问题的原因吗?

这是线程堆栈跟踪:

* thread #1: tid = 0x9f2b0, 0x01da9e15 libobjc.A.dylib`objc_retain + 21, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x5302f2fb)
frame #0: 0x01da9e15 libobjc.A.dylib`objc_retain + 21
* frame #1: 0x0000d14b Fader`-[MIDIController describeConnections](self=0x7c3c35b0, _cmd=0x00083ee3) + 683 at MIDIController.m:149
frame #2: 0x00049073 Fader`-[MainViewController internalReloadConnections:](self=0x7d0f6000, _cmd=0x000849f0, sender=0x7d0f6000) + 115 at MainViewController.m:1087
frame #3: 0x000494e0 Fader`-[MainViewController updateDisplay](self=0x7d0f6000, _cmd=0x000847c9) + 272 at MainViewController.m:1143
frame #4: 0x014e2119 Foundation`__NSFireTimer + 97
frame #5: 0x020bf8d6 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
frame #6: 0x020bf25d CoreFoundation`__CFRunLoopDoTimer + 1309
frame #7: 0x0207e6ba CoreFoundation`__CFRunLoopRun + 2090
frame #8: 0x0207dbcb CoreFoundation`CFRunLoopRunSpecific + 443
frame #9: 0x0207d9fb CoreFoundation`CFRunLoopRunInMode + 123
frame #10: 0x038d324f GraphicsServices`GSEventRunModal + 192
frame #11: 0x038d308c GraphicsServices`GSEventRun + 104
frame #12: 0x002b58b6 UIKit`UIApplicationMain + 1526
frame #13: 0x0000b06c Fader`main(argc=1, argv=0xbfff63f0) + 76 at main.m:14
frame #14: 0x02a6bac9 libdyld.dylib`start + 1

最佳答案

也许 [[MIDINetworkSession defaultSession] connections] 集合在您枚举时被改变了? (建立/断开 MIDI 连接)

快速枚举一个可变集合是不明智的,尤其是你不拥有的集合。我建议在开始时将它复制到 NSArray 中并枚举它

    - (NSString*) describeConnections {

// NSArray *tempConnections = [NSArray arrayWithArray: [[MIDINetworkSession defaultSession] connections] ];
//edit. replaced with line below, we are working with a set, not an array, see comments below..
NSArray *tempConnections = [[[MIDINetworkSession defaultSession] connections]allItems];

NSMutableArray* connections = [NSMutableArray arrayWithCapacity:[tempConnections count]];
for (MIDINetworkConnection* connection in tempConnections) {
[connections addObject:[[connection host] name]];
}
if ([connections count] > 0) {
return [connections componentsJoinedByString:@", "];
}
else{
return @"(Not connected)";

}

}

关于ios - MIDINetworkConnection EXC_BAD_ACCESS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27770188/

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