Skip to content

Commit

Permalink
fix: memory leak event error is not unsubscribing
Browse files Browse the repository at this point in the history
the event listener to scene `renderError` is only subscribing. causing memory leak upon cesium `.destory()`
  • Loading branch information
jony89 authored Feb 5, 2020
1 parent bc8b44e commit 4aa6bdf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Source/Widgets/CesiumWidget/CesiumWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,15 @@ import getElement from '../getElement.js';
this.targetFrameRate = options.targetFrameRate;

var that = this;
scene.renderError.addEventListener(function(scene, error) {
this._onRenderError = function(scene, error) {
that._useDefaultRenderLoop = false;
that._renderLoopRunning = false;
if (that._showRenderLoopErrors) {
var title = 'An error occurred while rendering. Rendering has stopped.';
that.showErrorPanel(title, undefined, error);
}
});
}
scene.renderError.addEventListener(this._onRenderError);
} catch (error) {
if (showRenderLoopErrors) {
var title = 'Error constructing CesiumWidget.';
Expand Down Expand Up @@ -671,6 +672,9 @@ import getElement from '../getElement.js';
* removing the widget from layout.
*/
CesiumWidget.prototype.destroy = function() {
if (this._scene) {
this._scene.renderError.removeEventListener(this._onRenderError);
}
this._scene = this._scene && this._scene.destroy();
this._container.removeChild(this._element);
this._creditContainer.removeChild(this._innerCreditContainer);
Expand Down

0 comments on commit 4aa6bdf

Please sign in to comment.