libpd/libpd — Issue #3: iOS PdBase evaluateFloatMessage crash
Author: reakinator
Created: 2011-11-30 10:47:07+00:00
State: open

This bug only happens on the device, reproducable on an iPhone 4s running iOS 5.0.

Steps using PdSettings example project:

* add the following delegate method to PdSettingsViewController (it is already set as the PdReceiverDelegate):

- (void)receiveFloat:(float)received fromSource:(NSString *)source {
}

* start the app on device, you'll get an EXC_BAD_ACCESS in the evaluateFloatMessage() function when trying to access p->x

Strange enough, memcpy'ing the float first works fine. To make the bug disappear in a most incorrect way, replace the existing evaluateFloatMessage() function with:

static void evaluateFloatMessage(params *p, void **buffer) {
if ([delegate respondsToSelector:@selector(receiveFloat:fromSource:)]) {
NSString *src = [[NSString alloc] initWithCString:p->src encoding:NSASCIIStringEncoding];
float f;
memcpy(&f, &p->x, sizeof(float));
[delegate receiveFloat:f fromSource:src];
[src release];
}
}