Re: MeteringView exc_bad_access
Re: MeteringView exc_bad_access
- Subject: Re: MeteringView exc_bad_access
- From: Hamilton Feltman <email@hidden>
- Date: Thu, 4 Nov 2010 16:12:13 -0700
It's just plain bad code. sizeof(meterValues) is returning 4 because that's the size of a float pointer, and it works in the MatrixMixerTest probably because of the stack layout of that temporary float array (the 2 values following the floats are "safe" for whatever reason). You could file a bug report against this sample code.
On Nov 3, 2010, at 12:30 PM, Graeme MacDonald wrote:
> Hi, I have dropped the MeteringView code from MatrixMixerTest into my own application and am continually getting EXC_BAD_ACCESS. Before that occurs, the meter does respond to audio, but never draws correctly. When I run it within MatrixMixerTest, all appears to be well.
>
> I'm guessing it's some sort of memory problem (I am no expert) and I've been trying to hunt down the problem. While looking at the code in MatrixMixerTest I'm confused by the following.
>
> In doTimer, this code is used (note 2 floats):
>
> float amps[2];
> err = AudioUnitGetParameter(mixer, kMatrixMixerParam_PostAveragePower, kAudioUnitScope_Input, i, &s[0]);
> err = AudioUnitGetParameter(mixer, kMatrixMixerParam_PostPeakHoldLevel, kAudioUnitScope_Input, i, &s[1]);
> value = sqrt(dbamp(value));
> [meter[i] updateMeters: amps];
>
> however, in the MeteringView class, in updateMeters, the code uses sizeof to get the number to iterate with. This returns 4 and as such meterValues has indices 0-3 applied against it. If the passed in array only has 2 floats in it, how can this work?
>
> Thanks.
>
> - (void) updateMeters: (float *) meterValues {
> if (![self inLiveResize]) {
> int numItems = sizeof(meterValues);
> for (int i = 0; i < numItems; i++) {
> float tempValue = dbamp(meterValues[i]);
> mOldMeterValues[i] = mMeterValues[i];
> float pixelValue = [self pixelForValue: tempValue inSize: (int) [self bounds].size.height];
> float top = [self bounds].size.height - (mHasClip ? kClipBoxHeight + 4: 2);
> if (pixelValue < 0)
> pixelValue = 0;
> else if (pixelValue > top)
> pixelValue = top;
>
> mMeterValues[i] = pixelValue;
> if (mHasClip) {
> if (tempValue > mMaxValue)
> mClipValues[i] = 1;
> }
> }
> drawsMetersOnly = YES;
> [self setNeedsDisplay: YES];
> }
> }
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coreaudio-api mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden