Issues writing to FREByteArray
I'm working on a native extension that reads in the contents of a file and writes those contents to a ByteArray for my application to use.
The data is being read fine, I've proven this by returning a string of what I'm reading, but I want this to handle data other than just text.
Here is the native code I'm using to write to the FREByteArray object:
FREObject retVal;
NSString *errorLevel;
NSData *fileData;
uint32_t location;
FREGetObjectAsUint32(argv[2], &location);
if (location > DSLocation_Temp) {
errorLevel = [NSString stringWithFormat:@"Unrecognised location %i", location];
FREDispatchStatusEventAsync(g_ctx, (uint8_t *)ARGUMENT_ERROR, (uint8_t *)[errorLevel UTF8String]);
FRENewObjectFromBool(NO, &retVal);
return retVal;
}
uint32_t pathLength;
const uint8_t *pathCString;
NSString *path = nil;
if (FRE_OK == FREGetObjectAsUTF8(argv[1], &pathLength, &pathCString)) {
path = [NSString stringWithUTF8String: (char*)pathCString];
}
BOOL success = [[DataStoreHelper helper] readData:&fileData atPath:path forLocation:location];
if (success) {
FREByteArray bytes;
FREAcquireByteArray(argv[0], &bytes);
uint8_t* nativestr = (uint8_t *)fileData.bytes;
memcpy(bytes.bytes, nativestr, 12);
FREReleaseByteArray(argv[0]);
}
else {
errorLevel = [[[DataStoreHelper helper] currentError] localizedDescription];
FREDispatchStatusEventAsync(g_ctx, (uint8_t *)DATA_WRITE_ERROR, (uint8_t *)[errorLevel UTF8String]);
}
FRENewObjectFromBool(success, &retVal);
return retVal;
Without fail this always crashes on the memcpy line. I've also tried using this exact code here and it crashes as well:
http://help.adobe.com/en_US/air/extensions/WS460ee381960520ad-866f9c112aa6e1ad46-7ff5.html
Here is the crash info from the device logs (grabbed from Xcode Organizer):
Incident Identifier: 69F45B8A-7123-4EAF-8A37-D4153821B2E5
CrashReporter Key: 26c3b0d6033ccf218b9d8de1aa872f71af680903
Hardware Model: iPad1,1
Process: ImaginaryFriends [17092]
Path: /var/mobile/Applications/3452D48C-C53B-4B3E-9066-AB9191BB2D8F/ImaginaryFriends.app/ImaginaryFriends
Identifier: ImaginaryFriends
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2012-07-18 16:56:08.390 -0400
OS Version: iPhone OS 5.1.1 (9B206)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_c.dylib 0x34a710d2 memcpy$VARIANT$CortexA8 + 946
