Skip to content

Commit

Permalink
Fixed exception 'this.el.node.getScreenCTM() is null' when cancel dra…
Browse files Browse the repository at this point in the history
…wing shape for any tracker (#8080)
  • Loading branch information
bsekachev committed Jun 25, 2024
1 parent 18aae08 commit ef0b366
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20240625_125241_boris.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Exception 'this.el.node.getScreenCTM() is null' when cancel drawing shape for any tracker
(<https://github.com/cvat-ai/cvat/pull/8080>)
43 changes: 31 additions & 12 deletions cvat-canvas/src/typescript/interactionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class InteractionHandlerImpl implements InteractionHandler {
private thresholdWasModified: boolean;
private controlPointsSize: number;
private selectedShapeOpacity: number;
private cancelled: boolean;

private prepareResult(): InteractionResult[] {
return this.interactionShapes.map(
Expand Down Expand Up @@ -193,6 +194,10 @@ export class InteractionHandlerImpl implements InteractionHandler {
this.canvas.on('mousedown.interaction', eventListener);
this.currentInteractionShape
.on('drawstop', (): void => {
if (this.cancelled) {
return;
}

this.canvas.off('mousedown.interaction', eventListener);
this.interactionShapes.push(this.currentInteractionShape);
this.shapesWereUpdated = true;
Expand Down Expand Up @@ -239,6 +244,11 @@ export class InteractionHandlerImpl implements InteractionHandler {
}

private release(): void {
if (this.currentInteractionShape && this.currentInteractionShape.remember('_paintHandler')) {
// Cancel active drawing first
(this.currentInteractionShape as any).draw('cancel');
}

if (this.drawnIntermediateShape) {
this.selectize(false, this.drawnIntermediateShape);
this.drawnIntermediateShape.remove();
Expand Down Expand Up @@ -529,20 +539,28 @@ export class InteractionHandlerImpl implements InteractionHandler {
}

public interact(interactionData: InteractionData): void {
if (interactionData.intermediateShape) {
this.intermediateShape = interactionData.intermediateShape;
this.updateIntermediateShape();
if (this.interactionData.startWithBox) {
this.interactionShapes[0].style({ visibility: 'hidden' });
if (interactionData.enabled) {
this.cancelled = false;
if (interactionData.intermediateShape) {
this.intermediateShape = interactionData.intermediateShape;
this.updateIntermediateShape();
if (this.interactionData.startWithBox) {
this.interactionShapes[0].style({ visibility: 'hidden' });
}
} else if (this.visualComponentsChanged(interactionData)) {
this.interactionData = { ...this.interactionData, ...interactionData };
this.initInteraction();
} else if (interactionData.enabled) {
this.interactionData = interactionData;
this.initInteraction();
this.startInteraction();
}
} else if (interactionData.enabled && this.visualComponentsChanged(interactionData)) {
this.interactionData = { ...this.interactionData, ...interactionData };
this.initInteraction();
} else if (interactionData.enabled) {
this.interactionData = interactionData;
this.initInteraction();
this.startInteraction();
} else {
if (this.currentInteractionShape && this.currentInteractionShape.remember('_paintHandler')) {
// Finish active drawing first if possible
(this.currentInteractionShape as any).draw('stop');
}

this.onInteraction(this.prepareResult(), this.shouldRaiseEvent(false), true);
this.release();
this.interactionData = interactionData;
Expand Down Expand Up @@ -571,6 +589,7 @@ export class InteractionHandlerImpl implements InteractionHandler {
}

public cancel(): void {
this.cancelled = true;
this.release();
this.onInteraction(null);
}
Expand Down

0 comments on commit ef0b366

Please sign in to comment.