Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure texture is not updated too early since these updates get lost silently #3262

Merged
merged 5 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
- Fixed a bug which caused a blank screen sometimes when the user is not logged in. [#3167](https://github.com/scalableminds/webknossos/pull/3167)
- Fixed a bug where NML downloads of Task Annotations failed. [#3166](https://github.com/scalableminds/webknossos/pull/3166)
- Fixed a bug where vieweing Compound Annotations (such as all tasks for a project in one view) failed. [#3174](https://github.com/scalableminds/webknossos/pull/3174)
- Fixed a bug which caused initial rendering to sometimes miss some buckets. [#3262](https://github.com/scalableminds/webknossos/pull/3262)

### Removed

Expand Down
23 changes: 15 additions & 8 deletions app/assets/javascripts/libs/UpdatableTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ UpdatableTexture.prototype.constructor = UpdatableTexture;

UpdatableTexture.prototype.isUpdatableTexture = true;

UpdatableTexture.prototype.setRenderer = function(renderer) {
UpdatableTexture.prototype.setRenderer = function setRenderer(renderer) {
this.renderer = renderer;
this.gl = this.renderer.getContext();
this.utils = THREE.WebGLUtils(this.gl, this.renderer.extensions);
};

UpdatableTexture.prototype.setSize = function(width, height) {
UpdatableTexture.prototype.setSize = function setSize(width, height) {
if (width === this.width && height === this.height) return;

const textureProperties = this.renderer.properties.get(this);
if (!textureProperties.__webglTexture) return;
if (!this.isInitialized()) return;

this.width = width;
this.height = height;

const activeTexture = this.gl.getParameter(this.gl.TEXTURE_BINDING_2D);
const textureProperties = this.renderer.properties.get(this);
this.gl.bindTexture(this.gl.TEXTURE_2D, textureProperties.__webglTexture);
if (!textureProperties.__webglTexture) this.width = null;
if (!this.isInitialized()) this.width = null;
this.gl.texImage2D(
this.gl.TEXTURE_2D,
0,
Expand All @@ -81,12 +81,19 @@ UpdatableTexture.prototype.setSize = function(width, height) {
this.gl.bindTexture(this.gl.TEXTURE_2D, activeTexture);
};

UpdatableTexture.prototype.update = function(src, x, y, width, height) {
UpdatableTexture.prototype.isInitialized = function isInitialized() {
return this.renderer.properties.get(this).__webglTexture != null;
};

UpdatableTexture.prototype.update = function update(src, x, y, width, height) {
this.setSize(width, width);
const textureProperties = this.renderer.properties.get(this);
if (!textureProperties.__webglTexture) return;
if (!this.isInitialized()) {
console.warn("Update called before texture was initialized. This update is discarded");
return;
}

const activeTexture = this.gl.getParameter(this.gl.TEXTURE_BINDING_2D);
const textureProperties = this.renderer.properties.get(this);
this.gl.bindTexture(this.gl.TEXTURE_2D, textureProperties.__webglTexture);
this.gl.texSubImage2D(
this.gl.TEXTURE_2D,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export default class TextureBucketManager {
this.freeIndexSet = new Set(_.range(this.maximumCapacity));

this.dataTextures = [];
}

startRAFLoops() {
this.keepLookUpBufferUpToDate();
this.processWriterQueue();
}
Expand Down Expand Up @@ -134,7 +136,7 @@ export default class TextureBucketManager {
}

keepLookUpBufferUpToDate() {
if (this.isRefreshBufferOutOfDate) {
if (this.lookUpTexture.isInitialized() && this.isRefreshBufferOutOfDate) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, it would be better to move this check into the startRAFLoops method and wait for the initialization of the texture, there :) Same for the check in the processWriterQueue method.

this._refreshLookUpBuffer();
}
window.requestAnimationFrame(() => {
Expand All @@ -157,7 +159,11 @@ export default class TextureBucketManager {
const bucketHeightInTexture = packedBucketSize / this.textureWidth;
const bucketsPerTexture = (this.textureWidth * this.textureWidth) / packedBucketSize;

while (performance.now() - startingTime < maxTimePerFrame && this.writerQueue.length > 0) {
while (
this.dataTextures[0].isInitialized() &&
performance.now() - startingTime < maxTimePerFrame &&
this.writerQueue.length > 0
) {
const { bucket, _index } = this.writerQueue.pop();
if (!this.activeBucketToIndexMap.has(bucket)) {
// This bucket is not needed anymore
Expand Down Expand Up @@ -207,6 +213,8 @@ export default class TextureBucketManager {
getRenderer(),
);
this.lookUpTexture = lookUpTexture;

this.startRAFLoops();
}

getLookUpBuffer() {
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/oxalis/model/data_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getLayerBoundaries,
getBitDepth,
} from "oxalis/model/accessors/dataset_accessor";
import ErrorHandling from "libs/error_handling";

// TODO: Non-reactive
class DataLayer {
Expand All @@ -37,6 +38,8 @@ class DataLayer {
const { dataset } = Store.getState();
const bitDepth = getBitDepth(getLayerByName(dataset, this.name));

ErrorHandling.assert(layerInfo.resolutions.length > 0, "Resolutions for layer cannot be empty");

this.cube = new DataCube(
getLayerBoundaries(dataset, this.name).upperBoundary,
layerInfo.resolutions.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ mock(
this.width = width;
this.height = height;
}

isInitialized() {
return true;
}
},
);

Expand Down