Smart ptr and count properties are undefined and zero

6 views
Skip to first unread message

Paulo Coutinho

unread,
Jan 11, 2023, 11:29:32 PM1/11/23
to emscripten-discuss
Hi,

I have a problem with smart-pointer. When i pass it for a JS function, the PTR is undefined and COUNT is undefined.

https://user-images.githubusercontent.com/395096/211975635-50b02139-b9ea-4130-995d-dcbf3ea1da44.png

The class that receive the smart-ptr is OK, but the method that receive a smart-ptr is wrong.

The bind code is:

```
EMSCRIPTEN_BINDINGS(xplpc_proxy_platform_proxy_callback)
{
    em::class_<xplpc::proxy::PlatformProxyCallback>("PlatformProxyCallback")
        .constructor<const std::function<void(const std::string &)> &&>()
        .smart_ptr<std::shared_ptr<xplpc::proxy::PlatformProxyCallback>>("shared_ptr<PlatformProxyCallback>")
        .function("call", &xplpc::proxy::PlatformProxyCallback::call);
}
```


File: https://github.com/xplpc/xplpc/blob/wasm-mapping/wasm/lib/src/bind.cpp#L33-L39

The javascript function is:

```
onRemoteProxyCallAsync: function (data: string, callback: XWebPlatformProxyCallback) {
    console.log("[XWebPlatformProxy : onRemoteProxyCallAsync] This: ", this);
    console.log("[XWebPlatformProxy : onRemoteProxyCallAsync] Callback: ", callback);
}
```


File: https://github.com/xplpc/xplpc/blob/wasm-mapping/wasm/sample/src/xplpc/proxy/platform-proxy.ts#L31-L33

The C++ code that call the JS function is:

```
void callProxyAsync(const std::string &data, std::shared_ptr<xplpc::proxy::PlatformProxyCallback> callback)
{
    // the count is 2
    spdlog::info("[callProxyAsync 1] Callback Smart Ptr Count: {}", callback.use_count());

    call<void>("onRemoteProxyCallAsync", data, callback);

    spdlog::info("[callProxyAsync 2]");
}
```


What im doing wrong? Thanks.

Reply all
Reply to author
Forward
0 new messages