float value changes when passed to function

Member
Posts: 306
Joined: 2009.03
Post: #1
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?
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #2
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...
Quote this message in a reply
Member
Posts: 144
Joined: 2009.11
Post: #3
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?

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #4
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
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.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #6
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Float vs Double bwalters 24 10,864 Jan 3, 2006 03:49 PM
Last Post: DoG