views:

39

answers:

1

Hey guys,

Something really weird is happening: when I call foo(100*1.0f), somewhere along the line that becomes 0. To verify I put a breakpoint on foo(), and it indeed is zero and it indeed gets called with 100*1.0f. The code is in Obj-C++.

Here is the calling function in XCode's GDB frontend, as you can see, score*scoreMultiplier is 100. Calling Function

void JNPP1PGameController::addScoreToPlayer(NSInteger score) {
    if(!gameOver){
        JNLogString(@"Adding score(%d*%f) to player", score, scoreMultiplier);
        [player addScore: score*scoreMultiplier];
        [wrapper setShouldNotify];
        [wrapper notify];
    } else {
        JNLogString(@"Not adding score(%d*%f) because GAME IS OVAR", score, scoreMultiplier);
    }
}

And here is the called function in XCode's GDB frontend, here _score is 0. Called Function

- (void) addScore:(NSInteger) _score {
    score += _score;
    JNLogString(@"Player can has %d points.. HURRAY!!!", score);
}
A: 

The code was fixed by changing the calling code to this:

void JNPP1PGameController::addScoreToPlayer(NSInteger score) {
    if(!gameOver){
        JNLogString(@"Adding score(%d*%f) to player", score, scoreMultiplier);
        NSInteger _score = score*scoreMultiplier;
        JNLogString(@"This is the case: %d", _score);
        [player addScore: _score];
        [wrapper setShouldNotify];
        [wrapper notify];
    } else {
        JNLogString(@"Not adding score(%d*%f) because GAME IS OVAR", score, scoreMultiplier);
    }
}

I assume now something went wrong with casting to a undefined (I got a "method not found" warning) parameter type.

Nick