I am trying to create a WebGL plugin and I read in the docs here: http://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html
But I'm not sure I understand.
I created a file in Assets/Plugins/WebGL called DomPlugin.jslib:
var DomPlugin = {
ReadFromDom: function()
{
var mapStr = document.getElementById('my-elm').innerText;
var buffer = _malloc(mapStr.length + 1);
writeStringToMemory(mapStr, buffer);
return buffer;
}
};
mergeInto(LibraryManager.library, DomPlugin);
Within one of my C# scripts, I created a method declaration like so:
[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern string ReadFromDom();
Then I call this external method like so:
private string ReadData()
{
if (Application.platform != RuntimePlatform.WebGLPlayer)
return testData.text;
return ReadFromDom();
}
My WebGL Template page has an element with ID my-elm defined above %UNITY_WEBGL_LOADER_GLUE%
When I deploy I find this error:
Invalid function pointer called with signature 'ii'. 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)