Calling javascript string function on browser from Unity returns null

微笑、不失礼 提交于 2019-12-06 09:35:39

This is your code:

GetEndpointURL: function()
{
    var endpoint = window.itd.getEndpointUrl();
    console.log("endpoint: " + endpoint);
    return endpoint;
}

You cannot return string (endpoint) directly. You have to create a buffer to hold that string and this process includes allocating memory with _malloc and copying old string to that new memory location with writeStringToMemory.

GetEndpointURL: function()
{
    var endpoint = window.itd.getEndpointUrl();
    console.log("endpoint: " + endpoint);

    var buffer = _malloc(lengthBytesUTF8(endpoint) + 1);
    writeStringToMemory(endpoint, buffer);
    return buffer;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!