Skip to content

Commit 9b4e9e7

Browse files
Merge pull request #32 from PixelsCommander/decomposition
Fixed memory leaks on RequestAnimationFrame
2 parents 2bdec4a + a42ce73 commit 9b4e9e7

6 files changed

Lines changed: 31 additions & 30 deletions

File tree

dist/htmlgl.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8531,7 +8531,6 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
85318531
w.HTMLGL.context = this;
85328532

85338533
this.createStage(); //Creating stage before showing it
8534-
console.log('context updated position');
85358534
this.updateScrollPosition(); //Initialize scroll position for first time
85368535
this.initListeners();
85378536
this.elementResolver = new w.HTMLGL.GLElementResolver(this);
@@ -8589,7 +8588,7 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
85898588
w.HTMLGL.scrollX = scrollOffset.left;
85908589
w.HTMLGL.scrollY = scrollOffset.top;
85918590

8592-
this.stage.changed = true;
8591+
this.markStageAsChanged();
85938592
}
85948593

85958594
p.createViewer = function () {
@@ -8612,7 +8611,8 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
86128611

86138612
this.renderer.resize(width, height);
86148613
this.updateTextures();
8615-
this.stage.changed = true;
8614+
8615+
this.markStageAsChanged();
86168616
}
86178617

86188618
p.createStage = function () {
@@ -8621,11 +8621,10 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
86218621
this.stage.addChild(w.HTMLGL.document);
86228622
}
86238623

8624+
//Avoiding function.bind() for performance and memory consuming reasons
86248625
p.redrawStage = function () {
8625-
requestAnimFrame(this.redrawStage.bind(this));
8626-
8627-
if (this.stage.changed) {
8628-
this.renderer.render(this.stage);
8626+
if (w.HTMLGL.stage.changed) {
8627+
w.HTMLGL.renderer.render(w.HTMLGL.stage);
86298628
w.HTMLGL.stage.changed = false;
86308629
}
86318630
}
@@ -8649,6 +8648,7 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
86498648
//We would like to rerender if something changed, otherwise stand by
86508649
p.markStageAsChanged = function () {
86518650
if (w.HTMLGL.stage && !w.HTMLGL.stage.changed) {
8651+
requestAnimFrame(this.redrawStage);
86528652
w.HTMLGL.stage.changed = true;
86538653
}
86548654
}

dist/htmlgl.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

page/css/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ html, body {
44
width: 100%;
55
margin: 0;
66
padding: 0;
7+
min-width: 930px;
78
}
89

910
body {

page/js/effects.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,28 +123,28 @@ var switchy = false;
123123

124124
function animate() {
125125

126-
count += 0.1;
126+
if (window.HTMLGL.scrollY > 1000) {
127+
count += 0.1;
127128

128-
var blurAmount = Math.cos(count) ;
129-
var blurAmount2 = Math.sin(count * 0.8) ;
129+
var blurAmount = Math.cos(count) ;
130+
var blurAmount2 = Math.sin(count * 0.8) ;
130131

131-
var filtersToApply = [];
132+
var filtersToApply = [];
132133

133-
filtersSwitchs[0] ? overlay.visible = true : overlay.visible = false;
134+
filtersSwitchs[0] ? overlay.visible = true : overlay.visible = false;
134135

135-
for (var i = 0; i < filterCollection.length; i++) {
136-
if(filtersSwitchs[i])filtersToApply.push(filterCollection[i]);
137-
};
136+
for (var i = 0; i < filterCollection.length; i++) {
137+
if(filtersSwitchs[i])filtersToApply.push(filterCollection[i]);
138+
};
138139

139-
pondContainer.filters = filtersToApply.length > 0 ? filtersToApply : null;
140+
pondContainer.filters = filtersToApply.length > 0 ? filtersToApply : null;
140141

141-
displacementFilter.offset.x = count * 10//blurAmount * 40;
142-
displacementFilter.offset.y = count * 10
142+
displacementFilter.offset.x = count * 10//blurAmount * 40;
143+
displacementFilter.offset.y = count * 10
143144

144-
overlay.tilePosition.x = count * -10//blurAmount * 40;
145-
overlay.tilePosition.y = count * -10
145+
overlay.tilePosition.x = count * -10//blurAmount * 40;
146+
overlay.tilePosition.y = count * -10
146147

147-
if (window.HTMLGL.scrollY > 1000) {
148148
renderer.render(stage);
149149
}
150150
requestAnimFrame( animate );

page/js/htmlgl.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gl-context.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
w.HTMLGL.context = this;
2525

2626
this.createStage(); //Creating stage before showing it
27-
console.log('context updated position');
2827
this.updateScrollPosition(); //Initialize scroll position for first time
2928
this.initListeners();
3029
this.elementResolver = new w.HTMLGL.GLElementResolver(this);
@@ -82,7 +81,7 @@
8281
w.HTMLGL.scrollX = scrollOffset.left;
8382
w.HTMLGL.scrollY = scrollOffset.top;
8483

85-
this.stage.changed = true;
84+
this.markStageAsChanged();
8685
}
8786

8887
p.createViewer = function () {
@@ -105,7 +104,8 @@
105104

106105
this.renderer.resize(width, height);
107106
this.updateTextures();
108-
this.stage.changed = true;
107+
108+
this.markStageAsChanged();
109109
}
110110

111111
p.createStage = function () {
@@ -114,11 +114,10 @@
114114
this.stage.addChild(w.HTMLGL.document);
115115
}
116116

117+
//Avoiding function.bind() for performance and memory consuming reasons
117118
p.redrawStage = function () {
118-
requestAnimFrame(this.redrawStage.bind(this));
119-
120-
if (this.stage.changed) {
121-
this.renderer.render(this.stage);
119+
if (w.HTMLGL.stage.changed) {
120+
w.HTMLGL.renderer.render(w.HTMLGL.stage);
122121
w.HTMLGL.stage.changed = false;
123122
}
124123
}
@@ -142,6 +141,7 @@
142141
//We would like to rerender if something changed, otherwise stand by
143142
p.markStageAsChanged = function () {
144143
if (w.HTMLGL.stage && !w.HTMLGL.stage.changed) {
144+
requestAnimFrame(this.redrawStage);
145145
w.HTMLGL.stage.changed = true;
146146
}
147147
}

0 commit comments

Comments
 (0)