Commit 7d54496e authored by Amanda Ghassaei's avatar Amanda Ghassaei

memory fixes

parent 1b583022
assets/attrib.txt assets/attrib.txt
.idea/
todo.rtf todo.rtf
\ No newline at end of file
...@@ -39,9 +39,10 @@ function initGPUMath(){ ...@@ -39,9 +39,10 @@ function initGPUMath(){
GPUMath.prototype.createProgram = function(programName, vertexShader, fragmentShader){ GPUMath.prototype.createProgram = function(programName, vertexShader, fragmentShader){
var programs = this.programs; var programs = this.programs;
var program = programs[name]; var program = programs[programName];
if (program) { if (program) {
console.warn("already a program with the name " + programName); gl.useProgram(program.program);
// console.warn("already a program with the name " + programName);
return; return;
} }
program = glBoilerplate.createProgramFromSource(gl, vertexShader, fragmentShader); program = glBoilerplate.createProgramFromSource(gl, vertexShader, fragmentShader);
...@@ -55,9 +56,13 @@ function initGPUMath(){ ...@@ -55,9 +56,13 @@ function initGPUMath(){
GPUMath.prototype.initTextureFromData = function(name, width, height, typeName, data, shouldReplace){ GPUMath.prototype.initTextureFromData = function(name, width, height, typeName, data, shouldReplace){
var texture = this.textures[name]; var texture = this.textures[name];
if (!shouldReplace && texture) {
console.warn("already a texture with the name " + name); if (texture){
return; if (!shouldReplace) {
console.warn("already a texture with the name " + name);
return;
}
gl.deleteTexture(texture);
} }
texture = glBoilerplate.makeTexture(gl, width, height, gl[typeName], data); texture = glBoilerplate.makeTexture(gl, width, height, gl[typeName], data);
this.textures[name] = texture; this.textures[name] = texture;
...@@ -67,9 +72,12 @@ function initGPUMath(){ ...@@ -67,9 +72,12 @@ function initGPUMath(){
GPUMath.prototype.initFrameBufferForTexture = function(textureName, shouldReplace){ GPUMath.prototype.initFrameBufferForTexture = function(textureName, shouldReplace){
var framebuffer = this.frameBuffers[textureName]; var framebuffer = this.frameBuffers[textureName];
if (framebuffer && (shouldReplace === undefined || !shouldReplace)) { if (framebuffer){
console.warn("framebuffer already exists for texture " + textureName); if (!shouldReplace) {
return; console.warn("framebuffer already exists for texture " + textureName);
return;
}
gl.deleteFramebuffer(framebuffer);
} }
var texture = this.textures[textureName]; var texture = this.textures[textureName];
if (!texture){ if (!texture){
......
...@@ -121,7 +121,7 @@ function initDynamicSolver(globals){ ...@@ -121,7 +121,7 @@ function initDynamicSolver(globals){
globals.shouldCenterGeo = false; globals.shouldCenterGeo = false;
} }
if (_numSteps == undefined) _numSteps = globals.numSteps; if (_numSteps === undefined) _numSteps = globals.numSteps;
for (var j=0;j<_numSteps;j++){ for (var j=0;j<_numSteps;j++){
solveStep(); solveStep();
} }
......
...@@ -32,16 +32,23 @@ function initModel(globals){ ...@@ -32,16 +32,23 @@ function initModel(globals){
setMeshMaterial(); setMeshMaterial();
function clearGeometries(){ function clearGeometries(){
if (geometry) geometry.dispose();
geometry = new THREE.BufferGeometry(); if (geometry) {
// geometry.dispose();
} else geometry = new THREE.BufferGeometry();
geometry.verticesNeedUpdate = true;
geometry.dynamic = true; geometry.dynamic = true;
frontside.geometry = geometry; frontside.geometry = geometry;
backside.geometry = geometry; backside.geometry = geometry;
_.each(lines, function(line){ _.each(lines, function(line){
if (line.geometry) line.geometry.dispose(); var lineGeometry = line.geometry;
var lineGeometry = new THREE.BufferGeometry(); if (lineGeometry) {
// line.geometry.dispose();
} else lineGeometry = new THREE.BufferGeometry();
lineGeometry.verticesNeedUpdate = true;
lineGeometry.dynamic = true; lineGeometry.dynamic = true;
line.geometry = lineGeometry; line.geometry = lineGeometry;
}); });
......
...@@ -141,7 +141,9 @@ function initThreeView(globals) { ...@@ -141,7 +141,9 @@ function initThreeView(globals) {
} }
function sceneClearModel(){ function sceneClearModel(){
modelWrapper.children = []; for (var i=0;i<modelWrapper.children.length;i++){
modelWrapper.remove(modelWrapper.children[i]);
}
} }
function onWindowResize() { function onWindowResize() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment