Fix null dereferencing issue. Fix sensor mode changed not clearing cached control.
This commit is contained in:
parent
81bfca4ed6
commit
3c4c38eb59
@ -94,6 +94,7 @@ namespace sensors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_update(prev: number, curr: number) {
|
_update(prev: number, curr: number) {
|
||||||
|
if (curr == null) return;
|
||||||
if (this.mode == ColorSensorMode.Color)
|
if (this.mode == ColorSensorMode.Color)
|
||||||
control.raiseEvent(this._id, this._colorEventValue(curr));
|
control.raiseEvent(this._id, this._colorEventValue(curr));
|
||||||
else
|
else
|
||||||
|
@ -5,6 +5,7 @@ namespace pxsim {
|
|||||||
|
|
||||||
protected mode: number;
|
protected mode: number;
|
||||||
protected valueChanged: boolean;
|
protected valueChanged: boolean;
|
||||||
|
protected modeChanged: boolean;
|
||||||
|
|
||||||
constructor(port: number) {
|
constructor(port: number) {
|
||||||
super(port);
|
super(port);
|
||||||
@ -24,6 +25,8 @@ namespace pxsim {
|
|||||||
|
|
||||||
setMode(mode: number) {
|
setMode(mode: number) {
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
this.changed = true;
|
||||||
|
this.modeChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
getMode() {
|
getMode() {
|
||||||
@ -44,6 +47,12 @@ namespace pxsim {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modeChange() {
|
||||||
|
const res = this.modeChanged;
|
||||||
|
this.modeChanged = false;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
setChangedState() {
|
setChangedState() {
|
||||||
this.changed = true;
|
this.changed = true;
|
||||||
this.valueChanged = false;
|
this.valueChanged = false;
|
||||||
|
@ -183,8 +183,8 @@ namespace pxsim.visuals {
|
|||||||
this.layoutView.updateTheme(theme);
|
this.layoutView.updateTheme(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getControlForNode(id: NodeType, port: number) {
|
private getControlForNode(id: NodeType, port: number, useCache = true) {
|
||||||
if (this.cachedControlNodes[id] && this.cachedControlNodes[id][port]) {
|
if (useCache && this.cachedControlNodes[id] && this.cachedControlNodes[id][port]) {
|
||||||
return this.cachedControlNodes[id][port];
|
return this.cachedControlNodes[id][port];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,7 +406,7 @@ namespace pxsim.visuals {
|
|||||||
if (view) {
|
if (view) {
|
||||||
const isSelected = EV3View.isPreviousInputSelected(index, node.id) || view.getSelected();
|
const isSelected = EV3View.isPreviousInputSelected(index, node.id) || view.getSelected();
|
||||||
if (isSelected && !view.getSelected()) view.setSelected(true);
|
if (isSelected && !view.getSelected()) view.setSelected(true);
|
||||||
const control = isSelected ? this.getControlForNode(node.id, index) : undefined;
|
const control = isSelected ? this.getControlForNode(node.id, index, !node.modeChange()) : undefined;
|
||||||
const closeIcon = control ? this.getCloseIconView() : undefined;
|
const closeIcon = control ? this.getCloseIconView() : undefined;
|
||||||
this.layoutView.setInput(index, view, control, closeIcon);
|
this.layoutView.setInput(index, view, control, closeIcon);
|
||||||
view.updateState();
|
view.updateState();
|
||||||
|
Loading…
Reference in New Issue
Block a user