dkrprasetya / simple-firebase-unity

Firebase Realtime-Database's REST API Wrapper for Unity in C#
143 stars 40 forks source link

Not working with webgl #18

Closed panpan1997 closed 6 years ago

panpan1997 commented 6 years ago

Cannot not send data to firebase Even i use your example and published to webgl, it will only stop for wait 15f but not get data or set value to firebase when I see the console of browser it show this problem:

{Error loading this URI: Could not load the source for blob:null/de1ec337-1122-4da9-b8d9-b0b175a890a2. [Exception... "Failed to open input source 'file:///de1ec337-1122-4da9-b8d9-b0b175a890a2'" nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame :: resource://devtools/shared/base-loader.js -> resource://devtools/shared/DevToolsUtils.js :: mainThreadFetch :: line 638" data: yes] Stack: mainThreadFetch@resource://devtools/shared/base-loader.js -> resource://devtools/shared/DevToolsUtils.js:638:5 _getSourceText/<@resource://devtools/shared/base-loader.js -> resource://devtools/server/actors/source.js:413:27 Line: 638, column: 0}

@dkrprasetya

dkrprasetya commented 6 years ago

Hmm, I'm suspecting the data to json encoding process (and vice versa) is the problem. I made it to work on different thread to prevent main thread blocking, but I suppose it doesn't work well on web gl. That's just my bet, I'll see if I could make time around this weekend.

Please let me know too if you found anything on this.

dkrprasetya commented 6 years ago

I made a change to handle the case for WebGL to not use threading here c067e46 (develop branch).

Seems like threading was the problem. I tested it on 2018.2 and it worked fine, will merge to master after few tests around this week. There's a lot of try-catch in the code so don't forget to enable exceptions on player settings.

I'll be very happy if you could help test it on your side too :) @panpan1997

antont commented 6 years ago

Yes, browser JS / WebAssembly runtimes do not currently support use of normal threads from web app code. Thanks for the fix, I hope it works, at least seems to be in master already! I will probably also test this on Monday.

For threading in web apps currently, you can use Web workers .. which are like threads, but do not share memory (are more like processes in that sense). The main app can send messages to workers and vice versa. A worker for JSON encoding would work ok, but maybe overkill if it does not take long.

Also, browsers include native code for JSON encoding which might be possible to use .. maybe the current C# solution is OK though.

Later, JS/WebAssembly is getting shared mem array & threading support but it's not there yet.

dkrprasetya commented 6 years ago

I'm not familiar with WebGL. This is very insightful for me, thank you :) Reading from here, implementing the web workers looks very feasible. Probably will try to implement this in the future, out of curiosity.

Since the platform case-handling working just fine, I will close this issue in a week, unless there's a new report on this case.