Skip to content

Commit

Permalink
fix(lights-effects): deadlock when passing undefined as color
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoronex committed Feb 3, 2025
1 parent 40454aa commit f579913
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/modules/lights/entities/colors-rgb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RgbColor, rgbColorDefinitions } from '../color-definitions';
import LightsFixtureShutterOptions, { ShutterOption } from './lights-fixture-shutter-options';
import Colors from './colors';
import { IColorsWheel } from './colors-wheel';
import logger from '../../../logger';

export type ColorChannel = keyof ColorsRgb;

Expand Down Expand Up @@ -56,8 +57,18 @@ export default class ColorsRgb extends Colors implements IColorsRgb {
uvChannel: 0,
};

public setColor(color: RgbColor): void {
this.currentValues = rgbColorDefinitions[color].definition;
public setColor(color?: RgbColor): void {
if (!color) {
this.reset();
return;
}
const spec = rgbColorDefinitions[color];
if (!spec) {
logger.error(`Color "${color}" not found in rgbColorDefinitions.`);
this.reset();
return;
}
this.currentValues = spec.definition;
}

public setCustomColor(color: IColorsRgb): void {
Expand Down
16 changes: 14 additions & 2 deletions src/modules/lights/entities/colors-wheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import LightsWheelRotateChannelValue from './lights-wheel-rotate-channel-value';
import { RgbColor, rgbColorDefinitions, WheelColor } from '../color-definitions';
import Colors from './colors';
import LightsFixtureShutterOptions, { ShutterOption } from './lights-fixture-shutter-options';
import logger from '../../../logger';

export interface IColorsWheel {
colorChannel: number;
Expand Down Expand Up @@ -46,8 +47,19 @@ export default class ColorsWheel extends Colors implements IColorsWheel {
goboRotateChannel: 0,
};

public setColor(color: RgbColor): void {
const wheelColor = rgbColorDefinitions[color].alternative;
public setColor(color?: RgbColor): void {
if (!color) {
this.reset();
return;
}
const spec = rgbColorDefinitions[color];
if (!spec) {
logger.error(`Color "${color}" not found in rgbColorDefinitions.`);
this.reset();
return;
}

const wheelColor = spec.alternative;
const channelValueObj = this.colorChannelValues.find((v) => v.name === wheelColor);
this.currentValues = {
...this.currentValues,
Expand Down

0 comments on commit f579913

Please sign in to comment.