iDevGames Forums
float value changes when passed to function - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: float value changes when passed to function (/thread-596.html)



float value changes when passed to function - kendric - Nov 14, 2009 08:51 PM

I am using cocos2d. While debugging an issue I discovered it was caused by the following:

cocos2d code:
check elapsed time for the tick event. If > whatever call my selector and pass time
Time is stored as a cctime which is typedef from a float

In my selector i also accept a cctime.

When I am stepping through the cocos code I see an expected value for time. When it calls my selector I see a value for time like 0.31231323x10^30

Anyone know why a selector with the same variable type might do this?


float value changes when passed to function - kendric - Nov 14, 2009 08:56 PM

Further investigation shows even stranger stuff going on here...
Code:
-(void) step: (ccTime) delta
{
    printf("Delta before %f\n",delta);
    delta=0.001f;
    printf("Delta after %f\n",delta);
    levelPassTime(level,delta);

First it won't even stop at a breakpoint on the delta= line
2nd if i stop at the levelPass line and inspect delta its value is various things but nothing anywhere close to what I just set it to... The print outs show:

Delta before 0.000000
Delta after 0.001000

Something funky this way comes...


float value changes when passed to function - cmiller - Nov 14, 2009 10:50 PM

kendric Wrote:Further investigation shows even stranger stuff going on here...
Code:
-(void) step: (ccTime) delta
{
    printf("Delta before %f\n",delta);
    delta=0.001f;
    printf("Delta after %f\n",delta);
    levelPassTime(level,delta);

First it won't even stop at a breakpoint on the delta= line
2nd if i stop at the levelPass line and inspect delta its value is various things but nothing anywhere close to what I just set it to... The print outs show:

Delta before 0.000000
Delta after 0.001000

Something funky this way comes...

Not quite. Something funky this way came.

http://www.cocos2d-iphone.org/forum/topic/2426

Try casting it to a float; perhaps you'll solve the problem?


float value changes when passed to function - kendric - Nov 15, 2009 09:14 AM

I think its due to some sort of assembled code and what I see being out of sync. WHen I run the same thing with it on the device instead of simulator its fine.


float value changes when passed to function - OneSadCookie - Nov 15, 2009 12:48 PM

I suspect it's due to you calling a function or method without a prototype. That'll happen to work on the device, and not on the simulator.

Use the warning settings from this page: http://www.idevgames.com/irc and fix the resulting errors.


float value changes when passed to function - kendric - Nov 15, 2009 01:57 PM

I figured this out. I had it set to release mode and I wasn't debugging the code I thought I was because I guess for release mode it compiles things into more efficient blocks.