diff --git a/test/demo/filtering-plugin/plugin.js b/test/demo/filtering-plugin/plugin.js index 566b9bbe..0a5dd27e 100644 --- a/test/demo/filtering-plugin/plugin.js +++ b/test/demo/filtering-plugin/plugin.js @@ -49,10 +49,6 @@ this.viewer = options.viewer; this.viewer.addHandler('tile-invalidated', applyFilters); - // filterIncrement allows to determine whether a tile contains the - // latest filters results. - this.filterIncrement = 0; - setOptions(this, options); async function applyFilters(e) { @@ -66,23 +62,12 @@ const contextCopy = await e.getData('context2d'); if (!contextCopy) return; - if (contextCopy.canvas.width === 0) { - debugger; - } - - try { - const currentIncrement = self.filterIncrement; - for (let i = 0; i < processors.length; i++) { - if (self.filterIncrement !== currentIncrement) { - break; - } - await processors[i](contextCopy); - } - - await e.setData(contextCopy, 'context2d'); - } catch (e) { - // pass, this is error caused by canvas being destroyed & replaced + for (let i = 0; i < processors.length; i++) { + if (e.outdated()) return; + await processors[i](contextCopy); } + if (e.outdated()) return; + await e.setData(contextCopy, 'context2d'); } }; @@ -99,7 +84,6 @@ filter.processors = $.isArray(filter.processors) ? filter.processors : [filter.processors]; } - instance.filterIncrement++; instance.viewer.requestInvalidate(); } diff --git a/test/demo/plugin-data-modification-interaction.html b/test/demo/plugin-data-modification-interaction.html index c1514769..07682d4b 100644 --- a/test/demo/plugin-data-modification-interaction.html +++ b/test/demo/plugin-data-modification-interaction.html @@ -109,7 +109,7 @@ window.pluginB = async function(e) { const canvas = ctx.canvas; ctx.fillStyle = "rgba(156, 0, 26, 0.4)"; ctx.fillRect(0, 0, canvas.width, canvas.height); - await tile.setData(ctx, 'context2d'); + await e.setData(ctx, 'context2d'); } }; // higher number = earlier execution