Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by PizzaGuy213 · Dec 02, 2018 at 09:27 PM · javascriptwebgl

Can't get WebGL to Interact with browser scripting

Hi all.

I keep getting errors when trying to interact with browser scripting.

I've followed a bunch of examples, but let's use the standard example from the Unity manual: https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html

Using Unity 2018.2.18f1

In a folder called Plugins I've created a file called test.jslib:

 mergeInto(LibraryManager.library, {
  
   Hello: function () {
     window.alert("Hello, world!");
   },
  
   HelloString: function (str) {
     window.alert(Pointer_stringify(str));
   },
  
   PrintFloatArray: function (array, size) {
     for(var i = 0; i < size; i++)
     console.log(HEAPF32[(array >> 2) + i]);
   },
  
   AddNumbers: function (x, y) {
     return x + y;
   },
  
   StringReturnValueFunction: function () {
     var returnStr = "bla";
     var bufferSize = lengthBytesUTF8(returnStr) + 1;
     var buffer = _malloc(bufferSize);
     stringToUTF8(returnStr, buffer, bufferSize);
     return buffer;
   },
  
   BindWebGLTexture: function (texture) {
     GLctx.bindTexture(GLctx.TEXTURE_2D, GL.textures[texture]);
   },
  
 });
  

I got a gameobject containt a script called NewBehaviourScript:

 using UnityEngine;
 using System.Runtime.InteropServices;
  
 public class NewBehaviourScript : MonoBehaviour {
  
     [DllImport("__Internal")]
     private static extern void Hello();
  
     [DllImport("__Internal")]
     private static extern void HelloString(string str);
  
     [DllImport("__Internal")]
     private static extern void PrintFloatArray(float[] array, int size);
  
     [DllImport("__Internal")]
     private static extern int AddNumbers(int x, int y);
  
     [DllImport("__Internal")]
     private static extern string StringReturnValueFunction();
  
     [DllImport("__Internal")]
     private static extern void BindWebGLTexture(int texture);
  
     void Start() {
         Hello();
      
         HelloString("This is a string.");
      
         float[] myArray = new float[10];
         PrintFloatArray(myArray, myArray.Length);
      
         int result = AddNumbers(5, 7);
         Debug.Log(result);
      
         Debug.Log(StringReturnValueFunction());
      
         var texture = new Texture2D(0, 0, TextureFormat.ARGB32, false);
         BindWebGLTexture(texture.GetNativeTextureID());
     }
 }
 

But when building and running the WebGL player I get this error:

 An error occurred running the Unity content on this page. See your browser JavaScript console for more info. The error was:
 uncaught exception: abort(-1) at jsStackTrace (TemplateTest.wasm.framework.unityweb:2:22127)
 stackTrace (TemplateTest.wasm.framework.unityweb:2:22298)
 onAbort@file:///D:/Thom/Unity/Arti/Projects/Builds/TemplateTest/Build/UnityLoader.js:4:10645
 abort (TemplateTest.wasm.framework.unityweb:2:481204)
 _Hello (TemplateTest.wasm.framework.unityweb:2:46724)
 @blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[27384]:0x8ad47d (blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[26720]:0x8a0acf)
 @blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[27676]:0x8c0345
 d38edf9076c603d4878e64a366122da4 [UnityLoader.d38edf9076c603d4878e64a366122da4/Module.dynCall_iiiii] (TemplateTest.wasm.framework.unityweb:2:1)
 invoke_iiiii (TemplateTest.wasm.framework.unityweb:2:354531)
 @blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[24271]:0x84f271 (blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[24625]:0x85c523)
 @blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[1925]:0x9a32d (blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[1924]:0x9a296)
 @blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[3415]:0x100cf7 (blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[3410]:0x100a05)
 @blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[6314]:0x267100 (blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[4101]:0x16ac7f)
 @blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[7056]:0x2b9599 (blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[6409]:0x270d9f)
 @blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[6409]:0x270db6 (blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[6404]:0x26ffcc)
 @blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[6398]:0x26e852 (blob:null/6a898df7-bfc2-4be5-b2d9-be16afff3d52 line 2 > WebAssembly.instantiate:wasm-function[24873]:0x866f5a)
 d38edf9076c603d4878e64a366122da4 [UnityLoader.d38edf9076c603d4878e64a366122da4/Module.dynCall_v] (TemplateTest.wasm.framework.unityweb:2:468735)
 browserIterationFunc (TemplateTest.wasm.framework.unityweb:2:131228)
 runIter (TemplateTest.wasm.framework.unityweb:2:134320)
 Browser_mainLoop_runner (TemplateTest.wasm.framework.unityweb:2:132765)

I've followed multiple other examples, as far as I could find them, but I've always seem to be getting these kind of errors.

Does it have something to do with WebAssembly? is the .jslib file incorrect? How would I get this to work?

Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

150 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Communication between WebGL and .jslib 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Unity WebGL UnityInstance.SendMessage Error: SendMessage: object Object1 does not have receiver for function moveObject 1 Answer

Unity WebGL calling a function from a jslib file in JavaScript(Vue) 0 Answers

Unity WebGL game on itch.io loads different scene than in editor 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges