Skip to content

Commit 899e2c5

Browse files
authored
Merge pull request #65 from De-Panther/shared_array_fix
Fixed memory growth related bug in shared arrays
2 parents 455ee2f + d2636b4 commit 899e2c5

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

Assets/WebXR/Plugins/WebGL/webxr.jslib

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
/* functions called from unity */
22
mergeInto(LibraryManager.library, {
33
InitXRSharedArray: function(byteOffset, length) {
4+
Module.XRSharedArrayOffset = byteOffset;
5+
Module.XRSharedArrayLength= length;
46
Module.XRSharedArray = new Float32Array(buffer, byteOffset, length);
57
document.dispatchEvent(new CustomEvent('UnityLoaded', {detail: 'Ready'}));
68
},
79

810
InitControllersArray: function(byteOffset, length) {
11+
Module.ControllersArrayOffset = byteOffset;
12+
Module.ControllersArrayLength= length;
913
Module.ControllersArray = new Float32Array(buffer, byteOffset, length);
1014
},
1115

1216
InitHandsArray: function(byteOffset, length) {
17+
Module.HandsArrayOffset = byteOffset;
18+
Module.HandsArrayLength= length;
1319
Module.HandsArray = new Float32Array(buffer, byteOffset, length);
1420
},
1521

1622
InitViewerHitTestPoseArray: function(byteOffset, length) {
23+
Module.ViewerHitTestPoseArrayOffset = byteOffset;
24+
Module.ViewerHitTestPoseArrayLength= length;
1725
Module.ViewerHitTestPoseArray = new Float32Array(buffer, byteOffset, length);
1826
},
1927

@@ -30,6 +38,9 @@ mergeInto(LibraryManager.library, {
3038
document.addEventListener('XRData', function(evt) {
3139
var data = evt.detail;
3240
var index = 0;
41+
if (Module.XRSharedArray.byteLength == 0) {
42+
Module.XRSharedArray = new Float32Array(buffer, Module.XRSharedArrayOffset, Module.XRSharedArrayLength);
43+
}
3344
Object.keys(data).forEach(function (key, i) {
3445
var dataLength = data[key].length;
3546
if (dataLength) {
@@ -42,6 +53,9 @@ mergeInto(LibraryManager.library, {
4253
document.addEventListener('XRControllersData', function(evt) {
4354
var data = evt.detail;
4455
var index = 0;
56+
if (Module.ControllersArray.byteLength == 0) {
57+
Module.ControllersArray = new Float32Array(buffer, Module.ControllersArrayOffset, Module.ControllersArrayLength);
58+
}
4559
Object.keys(data).forEach(function (key, i) {
4660
Module.ControllersArray[index++] = data[key].frame;
4761
Module.ControllersArray[index++] = data[key].enabled;
@@ -68,6 +82,9 @@ mergeInto(LibraryManager.library, {
6882
document.addEventListener('XRHandsData', function(evt) {
6983
var data = evt.detail;
7084
var index = 0;
85+
if (Module.HandsArray.byteLength == 0) {
86+
Module.HandsArray = new Float32Array(buffer, Module.HandsArrayOffset, Module.HandsArrayLength);
87+
}
7188
Object.keys(data).forEach(function (key, i) {
7289
Module.HandsArray[index++] = data[key].frame;
7390
Module.HandsArray[index++] = data[key].enabled;
@@ -90,6 +107,9 @@ mergeInto(LibraryManager.library, {
90107
document.addEventListener('XRViewerHitTestPose', function(evt) {
91108
var data = evt.detail;
92109
var index = 0;
110+
if (Module.ViewerHitTestPoseArray.byteLength == 0) {
111+
Module.ViewerHitTestPoseArray = new Float32Array(buffer, Module.ViewerHitTestPoseArrayOffset, Module.ViewerHitTestPoseArrayLength);
112+
}
93113
Module.ViewerHitTestPoseArray[index++] = data.viewerHitTestPose.frame;
94114
Module.ViewerHitTestPoseArray[index++] = data.viewerHitTestPose.available;
95115
Module.ViewerHitTestPoseArray[index++] = data.viewerHitTestPose.position[0];

Build/Build/Build.data.unityweb

0 Bytes
Binary file not shown.

Build/Build/Build.wasm

-449 Bytes
Binary file not shown.

Build/Build/Build.wasm.framework.unityweb

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)