Skip to content

Commit 2c8b8ec

Browse files
committed
fix(SimpleWeb.jslib): Remove Runtime from global scope
In unity 2021 LTS or later, Runtime is not defined by Unity, so a fix was to define it ourselves, but the code was defining it in global scope, so if a 2nd unity webgl instance is created then it would use the Runtime variable from the first one, which caused various errors. Dropping support for older unity versions means we can go back to using dynCall directly instead of calling via Runtime.dynCall
1 parent 3e61f5f commit 2c8b8ec

File tree

1 file changed

+4
-12
lines changed
  • Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/Webgl/plugin

1 file changed

+4
-12
lines changed

Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/Webgl/plugin/SimpleWeb.jslib

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ function IsConnected(index)
3131

3232
function Connect(addressPtr, openCallbackPtr, closeCallBackPtr, messageCallbackPtr, errorCallbackPtr)
3333
{
34-
// fix for unity 2021 because unity bug in .jslib
35-
if (typeof Runtime === "undefined")
36-
{
37-
// if unity doesn't create Runtime, then make it here
38-
// dont ask why this works, just be happy that it does
39-
var Runtime = { dynCall: dynCall }
40-
}
41-
4234
const address = UTF8ToString(addressPtr);
4335
console.log("Connecting to " + address);
4436

@@ -52,13 +44,13 @@ function Connect(addressPtr, openCallbackPtr, closeCallBackPtr, messageCallbackP
5244
webSocket.onopen = function(event)
5345
{
5446
console.log("Connected to " + address);
55-
Runtime.dynCall('vi', openCallbackPtr, [index]);
47+
dynCall('vi', openCallbackPtr, [index]);
5648
};
5749

5850
webSocket.onclose = function(event)
5951
{
6052
console.log("Disconnected from " + address);
61-
Runtime.dynCall('vi', closeCallBackPtr, [index]);
53+
dynCall('vi', closeCallBackPtr, [index]);
6254
};
6355

6456
webSocket.onmessage = function(event)
@@ -71,7 +63,7 @@ function Connect(addressPtr, openCallbackPtr, closeCallBackPtr, messageCallbackP
7163
var dataBuffer = new Uint8Array(HEAPU8.buffer, bufferPtr, arrayLength);
7264
dataBuffer.set(array);
7365

74-
Runtime.dynCall('viii', messageCallbackPtr, [index, bufferPtr, arrayLength]);
66+
dynCall('viii', messageCallbackPtr, [index, bufferPtr, arrayLength]);
7567
_free(bufferPtr);
7668
}
7769
else
@@ -83,7 +75,7 @@ function Connect(addressPtr, openCallbackPtr, closeCallBackPtr, messageCallbackP
8375
webSocket.onerror = function(event)
8476
{
8577
console.error('Socket Error', event);
86-
Runtime.dynCall('vi', errorCallbackPtr, [index]);
78+
dynCall('vi', errorCallbackPtr, [index]);
8779
};
8880

8981
return index;

0 commit comments

Comments
 (0)