app - >回调调用的扩展崩溃

时间:2013-04-18 14:23:15

标签: c++ marmalade marmalade-edk

我有一个Marmalade扩展和示例应用程序,它将C-callback从扩展程序传递给函数,所以当扩展试图调用该函数时会发生什么,它会以神秘的消息崩溃:

异常类型:EXC_BAD_ACCESS(SIGSEGV) 异常代码:KERN_INVALID_ADDRESS位于0x00000008 崩溃的线程:0

虽然,在我调用该函数之前,我打印它的地址,它是不同的,似乎有效。那么Marmalade限制还是我做错了什么?

p.s:值得注意的是我使用clang(而不是gcc)编译我的橘子酱扩展程序并且一切正常,但是回调...虽然之前我使用过默认的橘子酱gcc并且完全出现同样的问题。

示例应用:

class CDemoApp {
public:
    static CDemoApp* getInstance() {
        static CDemoApp instance;
        return &instance;
    }

    void setup()
    {
        app = CreateApp();
        window = CreateWindow();
        app->AddWindow(window);
        view = CreateView("canvas");

        button = CreateButton();

        button->SetEventHandler("click", (void*)NULL, CDemoApp::onButton1Click);

        view->AddChild(button);
        window->SetChild(view);

        app->ShowWindow(window);
    }

    void run() {
        app->Run();
    }

    static void onSDKInit(const char* err, void* context) {
        printf("Done.\n");
    }

    static bool onButton1Click(void* data, CButton* button) {
        if(!s3eMyExtDidInitialize()) {
            // crash happens here.
            // extension doesn't perform any ops, just calls the callback with dummy arguments
            s3eMyExtDoInitialize(APP_ID, APP_SECRET, CDemoApp::onSDKInit, NULL);
        }

        return true;
    }

private:
    CDemoApp() {};

private:
    CAppPtr app;
    CWindowPtr window;
    CViewPtr view;
    CButtonPtr button;
};

// Main entry point for the application
int main()
{
    if(!s3eMyExtAvailable())
    {
        s3eDebugErrorShow(S3E_MESSAGE_CONTINUE, "My extension is not found");
        return 0;
    }

    CDemoApp::getInstance()->setup();
    CDemoApp::getInstance()->run();

    return 0;
}

从扩展程序中公开的函数s3eMyExtDoInitialize如下所示:

typedef void (*my_callback)(const char* error, void* context);
void s3eMyExtDoInitialize_platform(const char* appId, const char* appSecret, my_callback callback, void* context) { 
    callback(NULL, NULL); 
}

1 个答案:

答案 0 :(得分:1)

好吧,显然没有办法直接从app传递一个函数指针到扩展,所以Marmalade提供了自己的回调系统,应该用它来让事情发挥作用。