开发者

Parameter becoming zero somewhere

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 http://img341.imageshack.us/img341/1109/screenshot20100502at135.png

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 http://img156.imageshack.us/img156/1109/screenshot20100502at135.png开发者_JAVA技巧

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜