gkngkc / UnityStandaloneFileBrowser

A native file browser for unity standalone platforms
MIT License
2.01k stars 317 forks source link

Not working on WebGL build? #11

Closed JoeriBultheel closed 6 years ago

JoeriBultheel commented 7 years ago

Seems to not be working for WebGL builds?

I get this error in my javascript console:

UnityLoader.js:1 exception thrown: RangeError: Maximum call stack size exceeded,RangeError: Maximum call stack size exceeded at ajo (blob:http://www.suchhacks.com/fbb5a1ce-c9e7-460a-93b7-98d3fd4c7ea5:18:480699) at Zio (blob:http://www.suchhacks.com/fbb5a1ce-c9e7-460a-93b7-98d3fd4c7ea5:18:476943) at $io (blob:http://www.suchhacks.com/fbb5a1ce-c9e7-460a-93b7-98d3fd4c7ea5:18:479001) at Zio (blob:http://www.suchhacks.com/fbb5a1ce-c9e7-460a-93b7-98d3fd4c7ea5:18:477043) at $io (blob:http://www.suchhacks.com/fbb5a1ce-c9e7-460a-93b7-98d3fd4c7ea5:18:479001) at Zio (blob:http://www.suchhacks.com/fbb5a1ce-c9e7-460a-93b7-98d3fd4c7ea5:18:477043) at $io (blob:http://www.suchhacks.com/fbb5a1ce-c9e7-460a-93b7-98d3fd4c7ea5:18:479001) at Zio (blob:http://www.suchhacks.com/fbb5a1ce-c9e7-460a-93b7-98d3fd4c7ea5:18:477043) at $io (blob:http://www.suchhacks.com/fbb5a1ce-c9e7-460a-93b7-98d3fd4c7ea5:18:479001) at Zio (blob:http://www.suchhacks.com/fbb5a1ce-c9e7-460a-93b7-98d3fd4c7ea5:18:477043)

... etc

gkngkc commented 7 years ago

I don't know exact cause, but this kind of exception is thrown when plugin js code unable find a method in c# side, so be sure "OnFileUploaded" or "OnFileDownloaded" (whichever you using) exist in caller script.

But again, i didn't test webgl much and it's probably buggy.

JoeriBultheel commented 7 years ago

Hm,

No I don't have any of those methods in my C# scripts... I can also not find any documentation on it. Is it part of the WWW or WWWForm classes? I can't find any method within unity with such names...

Thnx!

gkngkc commented 7 years ago

Sorry about undocumented code, those are my plugin methods called in here and here

Unity handles js communication with "SendMessage" and it needs a gameobject name and a method name to be able to call back. I'm sending gameobject name as parameter but method names are hardcoded. I should make them parameter too.

JoeriBultheel commented 7 years ago

Hey @gkngkc No worries, thank you so much for the fast answer!

I need it kind of urgently working on WebGL.

Could you just please explain me clearly what I should do next? On the same script that is calling the method "string path = StandaloneFileBrowser.OpenFilePanel("Open File", "", "", false)[0];" there should be a method "OnFileUploaded" or "OnFileDownloaded" ? What is the exact method signature? What should I implement in the body?

Thank you!!!

gkngkc commented 7 years ago

Due to browser limitations WebGL requires more work to open file dialog. It's not working with default "StandaloneFileBrowser.OpenFilePanel" call. You can find canvas upload/download examples at samples page

Browsers doesn't allow opening file dialogs unless user clicks a html element on page. Because of that, you need to call js plugin at Unity's "OnPointerDown" method. Plugin creates a html element and opens file dialog when user releases mouse, then js plugin calls unity side with sendmessage etc. It's a bit tricky but only way to open file dialogs on browsers

gkngkc commented 7 years ago

By the way, it's only supported by latest versions of chrome and firefox.

JoeriBultheel commented 7 years ago

heyhey, I got it semi working. The file browser is appearing. But now i get an error when clicking 'ok'. Any idea what it could mean?

Uncaught DOMException: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL at _JS_WebRequest_Create (blob:http://www.suchhacks.com/4b4d3bf7-706f-4d16-9cf1-2a490db247ca:2:211152) at NXb (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:11:351950) at xXb (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:11:340478) at Array.ZQc (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:15:1064293) at Wvo (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:4:804469) at Vvo (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:4:804333) at Array.F9n (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:4:613537) at Lun (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:4:71717) at Array.Eno (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:4:710488) at Array.Mxl (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:7:917178) at Object.bip [as dynCall_iiii] (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:28:410692) at invoke_iiii (blob:http://www.suchhacks.com/4b4d3bf7-706f-4d16-9cf1-2a490db247ca:2:358692) at BGf (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:22:826345) at JJf (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:22:855207) at Vca (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:10:89169) at Tca (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:10:88053) at C6a (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:12:37731) at z6a (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:12:36292) at v6a (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:12:35436) at JLc (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:15:1013057) at Array.ILc (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:15:1012755) at c5k (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:7:440834) at b5k (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:7:440716) at Array.y8n (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:4:589837) at Array.dUl (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:5:19317) at Object.bip [as dynCall_iiii] (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:28:410692) at invoke_iiii (blob:http://www.suchhacks.com/4b4d3bf7-706f-4d16-9cf1-2a490db247ca:2:358692) at BGf (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:22:826345) at JJf (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:22:855207) at Vca (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:10:89169) at Tca (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:10:88053) at t6a (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:12:33521) at s6a (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:12:29012) at vqb (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:12:1100980) at Toa (blob:http://www.suchhacks.com/26c8797c-4068-4dd3-bd3d-9a7299c1ebda:10:544954) at Object.ccallFunc [as ccall] (blob:http://www.suchhacks.com/4b4d3bf7-706f-4d16-9cf1-2a490db247ca:2:18502) at SendMessage (blob:http://www.suchhacks.com/4b4d3bf7-706f-4d16-9cf1-2a490db247ca:2:9557) at HTMLInputElement.fileInput.onchange (blob:http://www.suchhacks.com/4b4d3bf7-706f-4d16-9cf1-2a490db247ca:2:287210)

gkngkc commented 7 years ago

Looks like SendMessage throws the exception. Does your script's method name matches with js plugin's SendMessage parameter?

If it does, there is a chance that unity is stripping your methods.

JoeriBultheel commented 7 years ago

I think so,

I'm just using the method names of the example script like this :

    //
    // WebGL
    //
    [DllImport("__Internal")]
    private static extern void UploadFile(string id);

    public void OnPointerDown(PointerEventData eventData) {
    UploadFile(gameObject.name);
    }

    // Called from browser
    public void OnFileUploaded(string url) {
    StartCoroutine(OutputRoutine(url));
    }