Skip to content

Commit

Permalink
Fix: Channels effect crashes when setting alphaSource when source is …
Browse files Browse the repository at this point in the history
…undefined (#109)
  • Loading branch information
brianchirls committed Oct 29, 2015
1 parent f34009e commit 51ebea1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions effects/seriously.channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
s = inputs[name];
if (!s) {
s = me.sources[name] = inputs[name] = inputs.source;

if (!s) {
//no main source to fall back to
return;
}
}

j = sources.indexOf(s);
Expand Down
Binary file added test/media/tiny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions test/seriously.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3134,4 +3134,68 @@
start();
});
});

asyncTest('Channels', 5, function () {
require([
'seriously',
'effects/seriously.channels',
'sources/seriously.array'
], function (Seriously) {
var seriously,
effect,
target,
canvas,
pixels,
error,
incompatible,
array = [
255, 255, 255, 255,
255, 0, 0, 255,
0, 255, 0, 128,
0, 0, 255, 0
],
arraySource,
img,
imgSource,
expected;

incompatible = Seriously.incompatible();

seriously = new Seriously();
arraySource = seriously.source(array, {
width: 2,
height: 2
});

canvas = document.createElement('canvas');
canvas.width = canvas.height = 1;
target = seriously.target(canvas);

img = document.createElement('img');
img.src = 'media/tiny.png';
imgSource = seriously.source(img);

effect = seriously.effect('channels');
ok(effect, 'Channels effect successfully created');

effect.alphaSource = arraySource;
ok(true, 'Set alphaSource without having a main "source" input set (issue #109)');

effect.source = imgSource;
equal(effect.redSource, imgSource, 'Unset channel sources fall back to main "source" input');

effect.source = arraySource;
equal(effect.source, arraySource, 'Set main "source" a second time (issue #109)');
equal(effect.redSource, imgSource, 'Unset channel sources remain set to original main "source" even after it changes.');

target.source = effect;

//todo: render and readPixels to test accurate render results

seriously.destroy();
Seriously.removePlugin('channels');

start();
});
});
}());

0 comments on commit 51ebea1

Please sign in to comment.