Ocassional NPE in ColorThief.prototype.getColor
DallanQ opened this issue · comments
Every once in awhile, getPalette returns null, which causes palette[0] to throw an error.
ColorThief.prototype.getColor = function(sourceImage, quality) {
var palette = this.getPalette(sourceImage, 5, quality);
var dominantColor = palette[0];
return dominantColor;
};
I've created an issue on lokesh/color-thief#131 but I thought you'd like to know. It looks like getColor can just return null if palette is null; would that harm anything?
I haven't seen that error before.
It doesn't happen very often; maybe once a week. It could be related to a particular browser/OS combination, or maybe some weird way I'm using ngImgCropFullExtended; I don't know. But it looks like all you do with the result of getColor is set scope.dominantColor. You don't actually use scope.dominantColor, right?
i am not sure, i don't use that code before.
Thanks. I've just hacked around it: var dominantColor = !!palette ? palette[0] : null; hopefully that will solve the issue I'm getting.