#define IMPLEMENT_CALLBACK_FUNC_CB_ARG0(a,b) \
static void fgh##a##FuncCallback( FGCBUserData userData ) \
{ \
- FGCB##b callback = (FGCB##b)userData; \
- callback(); \
+ FGCB##b* callback = (FGCB##b*)&userData; \
+ (*callback)(); \
}
#define IMPLEMENT_CALLBACK_FUNC_CB_ARG1(a,b) \
static void fgh##a##FuncCallback( int arg1val, FGCBUserData userData ) \
{ \
- FGCB##b callback = (FGCB##b)userData; \
- callback( arg1val ); \
+ FGCB##b* callback = (FGCB##b*)&userData; \
+ (*callback)( arg1val ); \
}
#define IMPLEMENT_CALLBACK_FUNC_CB_ARG2(a,b) \
static void fgh##a##FuncCallback( int arg1val, int arg2val, FGCBUserData userData ) \
{ \
- FGCB##b callback = (FGCB##b)userData; \
- callback( arg1val, arg2val ); \
+ FGCB##b* callback = (FGCB##b*)&userData; \
+ (*callback)( arg1val, arg2val ); \
}
#define IMPLEMENT_CALLBACK_FUNC_CB_ARG3_USER(a,b,arg1,arg2,arg3) \
static void fgh##a##FuncCallback( arg1 arg1val, arg2 arg2val, arg3 arg3val, FGCBUserData userData ) \
{ \
- FGCB##b callback = (FGCB##b)userData; \
- callback( arg1val, arg2val, arg3val ); \
+ FGCB##b* callback = (FGCB##b*)&userData; \
+ (*callback)( arg1val, arg2val, arg3val ); \
}
#define IMPLEMENT_CALLBACK_FUNC_CB_ARG3(a,b) IMPLEMENT_CALLBACK_FUNC_CB_ARG3_USER(a,b,int,int,int)
#define IMPLEMENT_CALLBACK_FUNC_CB_ARG4(a,b) \
static void fgh##a##FuncCallback( int arg1val, int arg2val, int arg3val, int arg4val, FGCBUserData userData ) \
{ \
- FGCB##b callback = (FGCB##b)userData; \
- callback( arg1val, arg2val, arg3val, arg4val ); \
+ FGCB##b* callback = (FGCB##b*)&userData; \
+ (*callback)( arg1val, arg2val, arg3val, arg4val ); \
}
#define IMPLEMENT_CALLBACK_FUNC_CB_ARG5(a,b) \
static void fgh##a##FuncCallback( int arg1val, int arg2val, int arg3val, int arg4val, int arg5val, FGCBUserData userData ) \
{ \
- FGCB##b callback = (FGCB##b)userData; \
- callback( arg1val, arg2val, arg3val, arg4val, arg5val ); \
+ FGCB##b* callback = (FGCB##b*)&userData; \
+ (*callback)( arg1val, arg2val, arg3val, arg4val, arg5val ); \
}
/*
{ \
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glut"#a"Func" ); \
if( callback ) \
- glut##a##FuncUcall( fgh##a##FuncCallback, (FGCBUserData)callback ); \
+ { \
+ FGCB##b* reference = &callback; \
+ glut##a##FuncUcall( fgh##a##FuncCallback, *((FGCBUserData*)reference) ); \
+ } \
else \
glut##a##FuncUcall( NULL, NULL ); \
}
{
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTimerFunc" );
if( callback )
- glutTimerFuncUcall( timeOut, fghTimerFuncCallback, timerID, (FGCBUserData)callback );
+ {
+ FGCBTimer* reference = &callback;
+ glutTimerFuncUcall( timeOut, fghTimerFuncCallback, timerID, *((FGCBUserData*)reference) );
+ }
else
glutTimerFuncUcall( timeOut, NULL, timerID, NULL );
}
static void fghJoystickFuncCallback( unsigned int buttons, int axis0, int axis1, int axis2, FGCBUserData userData )
{
- FGCBJoystick callback = (FGCBJoystick)userData;
- callback( buttons, axis0, axis1, axis2 );
+ FGCBJoystick* callback = (FGCBJoystick*)&userData;
+ (*callback)( buttons, axis0, axis1, axis2 );
}
void FGAPIENTRY glutJoystickFunc( FGCBJoystick callback, int pollInterval )
{
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutJoystickFunc" );
if( callback )
- glutJoystickFuncUcall( fghJoystickFuncCallback, pollInterval, (FGCBUserData)callback );
+ {
+ FGCBJoystick* reference = &callback;
+ glutJoystickFuncUcall( fghJoystickFuncCallback, pollInterval, *((FGCBUserData*)reference) );
+ }
else
glutJoystickFuncUcall( NULL, pollInterval, NULL );
}
static void fghInitErrorFuncCallback( const char *fmt, va_list ap, FGCBUserData userData )
{
- FGError callback = (FGError)userData;
- callback( fmt, ap );
+ FGError* callback = (FGError*)&userData;
+ (*callback)( fmt, ap );
}
void FGAPIENTRY glutInitErrorFunc( FGError callback )
{
if (callback)
{
- glutInitErrorFuncUcall( fghInitErrorFuncCallback, (FGCBUserData)callback );
+ FGError* reference = &callback;
+ glutInitErrorFuncUcall( fghInitErrorFuncCallback, *((FGCBUserData*)reference) );
}
else
{
static void fghInitWarningFuncCallback( const char *fmt, va_list ap, FGCBUserData userData )
{
- FGWarning callback = (FGWarning)userData;
- callback( fmt, ap );
+ FGWarning* callback = (FGWarning*)&userData;
+ (*callback)( fmt, ap );
}
void FGAPIENTRY glutInitWarningFunc( FGWarning callback )
{
if (callback)
{
- glutInitWarningFuncUcall( fghInitWarningFuncCallback, (FGCBUserData)callback );
+ FGWarning* reference = &callback;
+ glutInitWarningFuncUcall( fghInitWarningFuncCallback, *((FGCBUserData*)reference) );
}
else
{
/* Standard glutCreateMenu */
static void fghCreateMenuCallback( int menu, FGCBUserData userData )
{
- FGCBMenu callback = (FGCBMenu)userData;
- callback( menu );
+ FGCBMenu* callback = (FGCBMenu*)&userData;
+ (*callback)( menu );
}
int FGAPIENTRY glutCreateMenu( FGCBMenu callback )
{
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateMenu" );
if (!callback)
- {
+ {
return glutCreateMenuUcall( NULL, NULL );
- }
- return glutCreateMenuUcall( fghCreateMenuCallback, (FGCBUserData)callback );
+ }
+ FGCBMenu* reference = &callback;
+ return glutCreateMenuUcall( fghCreateMenuCallback, *((FGCBUserData*)reference) );
}
/*