Skip to content

Commit 2ce170f

Browse files
authored
Fix to primitive caching to handle multi device/application scenario (playcanvas#2624)
1 parent dc2a29c commit 2ce170f

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/scene/procedural.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var primitiveUv1Padding = 4.0 / 64;
3636
var primitiveUv1PaddingScale = 1.0 - primitiveUv1Padding * 2;
3737

3838
// cached mesh primitives
39-
var shapePrimitiveMap = new Map();
39+
var shapePrimitives = [];
4040

4141
function calculateNormals(positions, indices) {
4242
var triangleCount = indices.length / 3;
@@ -1063,7 +1063,15 @@ function createBox(device, opts) {
10631063
// returns Primitive data, used by ModelComponent and RenderComponent
10641064
function getShapePrimitive(device, type) {
10651065

1066-
var primData = shapePrimitiveMap.get(type);
1066+
// find in cache
1067+
var primData = null;
1068+
for (var i = 0; i < shapePrimitives.length; i++) {
1069+
if (shapePrimitives[i].type === type && shapePrimitives[i].device === device) {
1070+
primData = shapePrimitives[i].primData;
1071+
}
1072+
}
1073+
1074+
// not in cache, create new
10671075
if (!primData) {
10681076

10691077
var mesh, area;
@@ -1104,7 +1112,13 @@ function getShapePrimitive(device, type) {
11041112
}
11051113

11061114
primData = { mesh: mesh, area: area };
1107-
shapePrimitiveMap.set(type, primData);
1115+
1116+
// add to cache
1117+
shapePrimitives.push({
1118+
type: type,
1119+
device: device,
1120+
primData: primData
1121+
});
11081122
}
11091123

11101124
return primData;

0 commit comments

Comments
 (0)