Before I submit a bug, I would like to ask if this is a known change from 5.5 to 5.6?
JSLIB that previously worked in 5.5, now breaks on line 16.
Was this expected?
exception thrown: ReferenceError: UNITY3D is not defined,UnityLoader["2258cc28bdc10989ac06d9afc30afa14"]/HGUNITY3DJS.Ready@blob:null/a0f4c54d-5622-ed4f-8b27-dfc125675cad:33:
Umm,
Test your project file in my 5.6.1p1.
I does not get “UNITY3D is not defined,UnityLoader” exception.
work in it.
You need delete HGUNITY3DJS.jslib first line.
(I think… because, library marge in emscripten context. emscripten context not have console.log())
and string argument get use Pointer_stringify()
You can not pass Unity with the blob type.
So it is necessary to convert from blob type to byte [ ] type (Uint8Array).
However, conversion from blob type to Uint8Array type can only be performed asynchronously.
Call the function by passing a callback function to receive asynchronous results.
using AOT;
using System;
using System.Runtime.InteropServices;
using UnityEngine;
public class test : MonoBehaviour {
[DllImport("__Internal")]
private static extern void getBlob(Action<IntPtr, int> callback);
[MonoPInvokeCallback(typeof(Action<IntPtr, int>))]
private static void resBlob(IntPtr ptr, int length)
{
var blobData = new byte[length];
Marshal.Copy(ptr, blobData, 0, length);
var tex = new Texture2D(1, 1);
tex.LoadImage(blobData);
GameObject.Find("ImagePreivew").GetComponent<Renderer>().material.mainTexture = tex;
}
void Start () {
getBlob(resBlob);
}
}
var testPlugin = {
getBlob: function (resBlob) {
var ret = blob;
// Load Image
fetch('/sample.png').then(function (res) {
return res.blob();
}).then(function (blob) {
// blob => Uint8Array => HEAPU8 => resBlob()
var fr = new FileReader();
fr.onload = function (evt) {
var ui8a = new Uint8Array(fr.result);
var ptr = _malloc(ui8a.byteLength);
HEAPU8.set(ui8a, ptr);
Runtime.dynCall('vii', resBlob, [ptr, ui8a.length]);
_free(ptr);
}
fr.readAsArrayBuffer(blob);
});
}
};
mergeInto(LibraryManager.library, testPlugin);