Skip to content

Commit

Permalink
Fix lost context
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Mar 1, 2024
1 parent 1e79e4e commit 847f6d4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/js/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Model = function (wrapper, canvas) {
}

// initialize render size for current canvas size
this.renderer.setSize(this.wrapper.width() * 2, this.wrapper.height() * 2);
this.renderer.setSize(this.wrapper.width(), this.wrapper.height());

// load the model including materials
let model_file = useWebGLRenderer ? mixerList[FC.MIXER_CONFIG.mixer - 1].model : 'fallback';
Expand Down Expand Up @@ -139,7 +139,7 @@ Model.prototype.render = function () {

// handle canvas resize
Model.prototype.resize = function () {
this.renderer.setSize(this.wrapper.width() * 2, this.wrapper.height() * 2);
this.renderer.setSize(this.wrapper.width(), this.wrapper.height());

this.camera.aspect = this.wrapper.width() / this.wrapper.height();
this.camera.updateProjectionMatrix();
Expand All @@ -148,9 +148,10 @@ Model.prototype.resize = function () {
};

Model.prototype.dispose = function () {
if (this.canUseWebGLRenderer()) {
this.renderer.forceContextLoss = null;
if (this.renderer) {
this.renderer.forceContextLoss();
this.renderer.dispose();
this.renderer = null;
}
};

Expand Down
9 changes: 6 additions & 3 deletions src/js/tabs/pid_tuning.js
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,10 @@ pid_tuning.initRatesPreview = function () {
};

pid_tuning.renderModel = function () {
if (this.keepRendering) { requestAnimationFrame(this.renderModel.bind(this)); }
if (!this.keepRendering) {
return;
}
requestAnimationFrame(this.renderModel.bind(this));

if (!this.clock) { this.clock = new THREE.Clock(); }

Expand Down Expand Up @@ -2346,15 +2349,15 @@ pid_tuning.renderModel = function () {
pid_tuning.cleanup = function (callback) {
const self = this;

self.keepRendering = false;

if (self.model) {
$(window).off('resize', $.proxy(self.model.resize, self.model));
self.model.dispose();
}

$(window).off('resize', $.proxy(this.updateRatesLabels, this));


self.keepRendering = false;
clearInterval(TABS.pid_tuning.throttleDrawInterval);

if (callback) callback();
Expand Down
9 changes: 6 additions & 3 deletions src/js/tabs/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,10 @@ receiver.initModelPreview = function () {
};

receiver.renderModel = function () {
if (this.keepRendering) { requestAnimationFrame(this.renderModel.bind(this)); }
if (this.keepRendering) {
return;
}
requestAnimationFrame(this.renderModel.bind(this));

if (!this.clock) { this.clock = new THREE.Clock(); }

Expand All @@ -874,14 +877,14 @@ receiver.renderModel = function () {
};

receiver.cleanup = function (callback) {
this.keepRendering = false;

$(window).off('resize', this.resize);
if (this.model) {
$(window).off('resize', $.proxy(this.model.resize, this.model));
this.model.dispose();
}

this.keepRendering = false;

if (callback) callback();
};

Expand Down

0 comments on commit 847f6d4

Please sign in to comment.