Germán Hofer
Germán Hofer

Reputation: 9

Objective-C - BAD ACCESS EXC

I am trying to create a project that uses audio streaming from unity. For this, I am developing a plugin.

At the time of recording the audio has no problem and I send the data through a websocket in a base64 string. Then from xcode I catch it and transform it to NSDATA, that's the problem. At first there are no problems but after a moment, Xcode show me the error EXC_BAD_ACCESS and I can't continue copying the NSDATA into the buffer.

Here is the code.

#import "AudioProcessor.h"  

#pragma mark Playback callback  

static OSStatus playbackCallback(void *inRefCon,  
                             AudioUnitRenderActionFlags *ioActionFlags,  
                             const AudioTimeStamp *inTimeStamp,  
                             UInt32 inBusNumber,  
                             UInt32 inNumberFrames,  
                             AudioBufferList *ioData) {  


AudioProcessor audioProcessor = (AudioProcessor) inRefCon;  

// copy buffer to audio buffer which gets played after function return  
if(ioData->mNumberBuffers > 0) {  

     AudioBuffer buffer = ioData->mBuffers[0];  

     // get the data from Unity  
     NSString *inputData = audioProcessor.getInputData;  

    if(inputData && ![inputData isKindOfClass:[NSNull class]])  
    {  

        //here it's the problem.  
        NSData *data = [[NSData alloc] initWithBase64EncodedString:inputData options:0];  

        memcpy(buffer.mData, data.bytes, data.length);  
        buffer.mDataByteSize = (int) data.length;  
        free(data);
    }  

return noErr;  
}  

#pragma mark controll stream  

-(void)setInputData:(NSString *)datosValue  
{  
  inputData = datosValue;  
}  

-(NSString*)getInputData  
{  
  return inputData;  
}  

If someone knows how it could be done so that the application does not close, I would appreciate it.

Upvotes: 0

Views: 495

Answers (1)

vadian
vadian

Reputation: 285059

First of all please conform to the naming convention that variable names start with a lowercase letter.

The error occurs because an instance of NSData is an object / a pointer, you have to add a *

NSData *data = [[NSData alloc] init....

Further it's highly recommended to access properties with dot notation for example

data.bytes
data.length

Upvotes: 1

Related Questions