In native compilers this is undefined behavior that happens to work
properly, at least most of the time.

In emscripten you can try the EMULATE_FUNCTION_POINTER_CASTS option. It
adds overhead, but can cast to the proper type at runtime.

On Wed, Apr 5, 2017 at 3:14 AM, caiiiycuk <[email protected]> wrote:

> Hi! Cocos2d use special macro to cast different function pointers to
> universal handler format:
>
> typedef void (Object::*SEL_MenuHandler)(Object*);
>> #define menu_selector(_SELECTOR) (cocos2d::SEL_MenuHandler)(&_SELECTOR)
>
>
>
> With this *menu_selector* macro I can cast many different function signatures 
> to SEL_MenuHandler.
>
> For example:
>
> void MyObject::soundOff1()
>> void MyObject::soundOff2(Object* sender)
>> void MyObject::soundOff3(MenuItemImage* sender) // MenuItemImage is
>> subclass of Object
>> // ...
>> menu_selector(myobj::soundOff1)
>> menu_selector(myobj::soundOff2)
>> menu_selector(myobj::soundOff3)
>
>
> Casting like this widely used in cocos2d projects, and works fine in native 
> environment.
>
> But when I use code like this under emscripten environment I have fatal 
> errors like this:
>
>
> Invalid function pointer '1551' called with signature 'vid'. Perhaps this
>> is an invalid value (e.g. caused by calling a virtual method on a NULL
>> pointer)? Or calling a function with an incorrect type, which will fail?
>> (it is worth building your source files with -Werror (warnings are errors),
>> as warnings can indicate undefined behavior which can cause this)
>> bin.html:1249:13
>> This pointer might make sense in another type signature: vi:
>> __ZN13Choose_screen12lock_checkerEv vidd: 0 v: 0 viddi: 0 vidddd: 0
>> viid: 0 vii: 0 idd: 0 i: 0 ii: 0 di: 0 viii: 0 iiid: 0 iii: 0 dii: 0 viiii:
>> 0 viiidi: 0 iiii: 0 diii: 0 viiiii: 0 iiiidd: 0 iiiiid: 0 iiiii: 0 viiiiii:
>> 0 iiiiii: 0 iiiiiid: 0 iiiiddd: 0 iiiiiii: 0 viiiiiii: 0 iiiiiiid: 0
>> iiiiiiii: 0 viiiiiiii: undefined iiiiiiiii: 0 viiiiiiiii: 0 viiiiiiiiii: 0
>> iiiiiiiiiii: 0 iiiiiiiiiiii: 0 iiiiiiiiiiiii: 0 viiiiiiiiiiiiiii: 0
>
>
> To avoid this problems by replacing *menu_selector* macro with this:
>
> #define menu_selector(_SELECTOR) static_cast<cocos2d::SEL_
>> MenuHandler>(&_SELECTOR)
>
>
> and rewriting code, but usually in cocos2d projects a lot of places should
> be fixed to adapt new macros.
> Can I solve this problem in other way (call this function by name and
> ignore signature)? I wonder how this managed in native compiler.
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to