Kaynağa Gözat

Merge pull request #20643 from takahirox/FixMemoryLeak

WebGLBindingStates: Resolve memory leak caused by using Object.keys()
Mr.doob 4 yıl önce
ebeveyn
işleme
84b7a634fc
1 değiştirilmiş dosya ile 9 ekleme ve 1 silme
  1. 9 1
      src/renderers/webgl/WebGLBindingStates.js

+ 9 - 1
src/renderers/webgl/WebGLBindingStates.js

@@ -169,7 +169,7 @@
 		const cachedAttributes = currentState.attributes;
 		const geometryAttributes = geometry.attributes;
 
-		if ( Object.keys( cachedAttributes ).length !== Object.keys( geometryAttributes ).length ) return true;
+		let attributesNum = 0;
 
 		for ( const key in geometryAttributes ) {
 
@@ -182,8 +182,12 @@
 
 			if ( cachedAttribute.data !== geometryAttribute.data ) return true;
 
+			attributesNum ++;
+
 		}
 
+		if ( currentState.attributesNum !== attributesNum ) return true;
+
 		if ( currentState.index !== index ) return true;
 
 		return false;
@@ -194,6 +198,7 @@
 
 		const cache = {};
 		const attributes = geometry.attributes;
+		let attributesNum = 0;
 
 		for ( const key in attributes ) {
 
@@ -210,9 +215,12 @@
 
 			cache[ key ] = data;
 
+			attributesNum ++;
+
 		}
 
 		currentState.attributes = cache;
+		currentState.attributesNum = attributesNum;
 
 		currentState.index = index;