Re: Class gets EXC_BAD_ACCESS only as NSOperation
Re: Class gets EXC_BAD_ACCESS only as NSOperation
- Subject: Re: Class gets EXC_BAD_ACCESS only as NSOperation
- From: James Maxwell <email@hidden>
- Date: Tue, 24 Mar 2009 08:22:56 -0700
- (void) trainNetworkOnMIDIData
{
NSArray *pitchSlices = [[self MIDITrainingData] objectAtIndex:0];
NSArray *rhythmSlices = [[self MIDITrainingData] objectAtIndex:1];
int sliceCount = [pitchSlices count];
float midiEventsToHTM[sliceCount][20];
float rhythmEventsToHTM[sliceCount][20];
int i,j,k;
for(i=0;i < sliceCount;i++)
{
for(j=0;j < 10;j++)
{
int slot = j * 2;
midiEventsToHTM[i][slot] = [[[pitchSlices objectAtIndex:i]
objectAtIndex:slot] floatValue];
midiEventsToHTM[i][slot+1] = [[[pitchSlices objectAtIndex:i]
objectAtIndex:slot+1] floatValue];
exc_bad_access --> rhythmEventsToHTM[i][slot] = [[[rhythmSlices
objectAtIndex:i] objectAtIndex:slot] floatValue];
rhythmEventsToHTM[i][slot+1] = [[[rhythmSlices objectAtIndex:i]
objectAtIndex:slot+1] floatValue];
}
}
// does more stuff, but it's crashed by now...
}
The rhythmEventsToHTM array is the one that's getting the bad access
error, and I can NSLog the rhythmSlices NSArray without issue. The
other thing that seems very weird is that, if I just run the
midiEventsToHTM data (i.e., commenting out anything to do with
"rhythm") it runs fine in either the main thread or the NSOperation
thread. (Just as a note, pitchSlices and rhythmSlices are always the
same length.) Since I'm sending the whole "network" to the
NSOperation, the new thread should have all the data it needs to do
its thing - really this is just [self MIDITrainingData]. (And besides,
I can NSLog all of [self MIDITrainingData] without issue.)
I'm running the thread like this:
HTMTrainingOperation *trainingOperation = [[HTMTrainingOperation
alloc] initWithNetwork:self];
NSOperationQueue *trainingQueue = [[NSOperationQueue alloc] init];
[trainingQueue addOperation:trainingOperation];
[trainingOperation release];
Don't know if that's enough code to make sense of what's up...
thanks,
J.
On 24-Mar-09, at 7:53 AM, Bill Bumgarner wrote:
On Mar 24, 2009, at 7:33 AM, James Maxwell wrote:
I have a method that I want to run in the background. When I run it
in the app's main thread, all's well, but when I run it as an
NSOperation I get an EXC_BAD_ACCESS error. The error happens when
trying to initialize a local float array.
Simplify the problem; you have a "local float array" that "all's
well on main thread", but it crashes when "run in the background".
OK -- NSOperation is a red herring.
You have a multithreading bug related to a simple data type.
So...
How do you initialize the float array? ... from main thread, used
on background thread?
What other synchronization points do you have? ... what other data
is shared?
Show some code?
b.bum
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden