Thread: SDL_Timer

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    55

    SDL_Timer

    I'm trying to use SDL_AddTimer or SDL_SetTimer, it's the same... My problem is that I don't know what I'm doing wrong with the callback function... I have this method:

    Code:
    Uint32 showNextFrame(Uint32 interval,void*param){
    
    .........
    
    return interval
    }

    And then on another method within the same class I have:

    Code:
    SDL_AddTimer(30,showNextFrame, NULL);


    I'm getting this error:

    error C2664: 'SDL_AddTimer' : cannot convert parameter 2 from 'unsigned __int32 (unsigned __int32,void *)' to 'unsigned __int32 (__cdecl *)(unsigned __int32,void *)'

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    You have to declare the showNextFrame() function as "__cdecl Uint32"

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    55
    Doesn't seem to be working... The first error it shows me now is:

    error C2146: syntax error : missing ';' before identifier 'showNextFrame'

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by manugarciac View Post
    Doesn't seem to be working... The first error it shows me now is:

    error C2146: syntax error : missing ';' before identifier 'showNextFrame'
    I need to see the line of code.

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    55
    Code:
    __cdecl Uint32 showNextFrame(Uint32 interval,void*param){
    ....
    }

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    55
    I noticed that if I take it out of the class and use it as a global function, it works... Do you have any idea how to make it work without having to do that?

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by manugarciac View Post
    I noticed that if I take it out of the class and use it as a global function, it works... Do you have any idea how to make it work without having to do that?
    I don't think an SDL callback can be an object method. It would have no way of knowing what the "this" pointer is, since C++ doesn't have such a concept as a bound method pointer.

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    55
    I guess you are right... And I can't take the function out, it'd completely mess my encapsulation... What do you recommend? I have a set of bmps, that act like different frames in a video... Suppose I have to show them at 20fps, that would mean I need to show the next frame every 50ms. That's why I was trying to use those functions... Do you have any ideas?

Popular pages Recent additions subscribe to a feed