I try to pass CGRect to NSInvocation (setArgument:atIndex:). I wrap it by NSValue, push to the NSArry,then get from NSArray and use NSValue (getValue:). Calling of (getValue
You can't fit an NSRect into a void*. The correct code would be:
NSRect buffer;
[currentVal getValue:&buffer];
Or alternatively, if you don't know the contents of the NSValue object:
NSUInteger bufferSize = 0;
NSGetSizeAndAlignment([currentVal objCType], &bufferSize, NULL);
void* buffer = malloc(bufferSize);
[currentVal getValue:buffer]; //notice the lack of '&'
//do something here
free(buffer);
The value for i is changing because your code causes an overflow into other stack-allocated variables.