So I am trying to get a callback setup in Objective-C. I am use to C++ so I keep hitting this stuff the wrong way. I found this answer and have been trying to model my code in the same way.
How to perform Callbacks in Objective-C
However when in my 'LocationActivated' function the xCoord and yCoord seem to have the complete wrong values.
delegate.mm
- (void)Initialize {
[mWorldObj RegisterActivateDelegate: self];
}
-(void) LocationActivated :(float)xCoord :(float)yCoord {
int a;
a++;
pLocation.center = CGPointMake(xCoord, yCoord);
}
delegate.h
-(void) LocationActivated :(float)xCoord :(float)yCoord;
world.h
id mActivateDelegate;
Delegate call in world.mm
float msgarr[2];
msgarr[0] = (float)((camera.VideoWidth() * 0.5f) + projX) + curLoc->mPopOffsetX;
msgarr[1] = (float)((camera.VideoHeight() * 0.5f) - projY) + curLoc->mPopOffsetY;
if(mActivateDelegate != null) {
[mActivateDelegate LocationActivated :msgarr[0] :msgarr[1]];
}
When calling msgarg[0] and [1] are completely valid values, ~(200, 200). But when in the callback the values are now completely different. I dumped the memory on both sides and didn't see any commonalities so my best guess is I am doing the function call totally wrong.
I also get a warning on the [mActivateDelegate LocationActivated] line saying 'Location Activated may not repsond' which makes sense because as far as the compiler knows mActiveDelegate is of type 'id'.
Any idea what I am doing wrong? Better way to approach this?
Edit:
Adding Register function from delegate.mm
- (void)RegisterActivateDelegate :(id) delegate {
mActivateDelegate = delegate;
}