We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1925 - SDL_GetPerformanceFrequency - returns 0
Summary: SDL_GetPerformanceFrequency - returns 0
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: timer (show other bugs)
Version: don't know
Hardware: iPhone/iPod touch iOS (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-21 09:00 UTC by PoopiSan
Modified: 2013-08-10 15:17 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description PoopiSan 2013-06-21 09:00:13 UTC
SDL_GetPerformanceFrequency is incorrectly implemented on Apple machines.

Currently on OSX and iOS simulator the values:
mach_base_info.denom = 1
mach_base_info.numer = 1

but on the real iOS device
mach_base_info.denom = 3
mach_base_info.numer = 125

The calculation is made using following formula
mach_base_info.denom / mach_base_info.numer * 1000000

but all values are int32 and the result is casted to int64.

This solves the problem:

return 1.0 * mach_base_info.denom / mach_base_info.numer * 1000000;
Comment 1 Sam Lantinga 2013-06-24 01:23:23 UTC
Thanks for the report!
This should be fixed:
http://hg.libsdl.org/SDL/rev/c3052ed2c310
Comment 2 sofmz 2013-08-10 01:43:43 UTC
it doesn't seem to be fixed yet. I've downloaded the latest snapshot(SDL-2.0.0-7602), it doesn't return 0 anymore but a weird number.


I've fixed it by changing it to : 

#elif defined(__APPLE__)
        return (mach_base_info.denom * 1000000) / mach_base_info.numer;
#endif


from 


#elif defined(__APPLE__)
        Uint64 freq = mach_base_info.numer;
        freq *= 1000000000;
        freq /= mach_base_info.denom;
        return freq;
#endif
Comment 3 Sam Lantinga 2013-08-10 02:10:10 UTC
It works for me here.

What's the output of this code for you?
    Uint32 start32, now32;
    Uint64 start, now;

    printf("Performance counter frequency: %llu\n", (unsigned long long) SDL_GetPerformanceFrequency());
    start32 = SDL_GetTicks();
    start = SDL_GetPerformanceCounter();
    SDL_Delay(1000);
    now = SDL_GetPerformanceCounter();
    now32 = SDL_GetTicks();
    printf("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (now32-start32), (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
Comment 4 sofmz 2013-08-10 03:08:47 UTC
(In reply to comment #3)
> It works for me here.
> 
> What's the output of this code for you?
>     Uint32 start32, now32;
>     Uint64 start, now;
> 
>     printf("Performance counter frequency: %llu\n", (unsigned long long)
> SDL_GetPerformanceFrequency());
>     start32 = SDL_GetTicks();
>     start = SDL_GetPerformanceCounter();
>     SDL_Delay(1000);
>     now = SDL_GetPerformanceCounter();
>     now32 = SDL_GetTicks();
>     printf("Delay 1 second = %d ms in ticks, %f ms according to performance
> counter\n", (now32-start32), (double)((now - start)*1000) /
> SDL_GetPerformanceFrequency());


The SDL_GetPerformanceFrequency code in snapshot SDL-2.0.0-7602 works correctly on simulator only but not on real iOS devices.

Btw, this is the output I've tested on my iPad : 

Delay 1 second = 1025 ms in ticks, 0.590138 ms according to performance counter
Performance counter frequency: 41666666666
Comment 5 Sam Lantinga 2013-08-10 14:20:02 UTC
Fixed, thanks for checking this! :)
http://hg.libsdl.org/SDL/rev/ebf5f6859e40
Comment 6 sofmz 2013-08-10 15:17:21 UTC
No problem! I'm glad it helps. :)