Skip to content

Commit

Permalink
Fixed: Cannot read properties of null (reading 'draw') (cvat-ai#7997)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev authored Jun 12, 2024
1 parent b1ddc1e commit 14b65ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20240606_194542_sekachev.bs_fixed_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Cannot read properties of null (reading 'draw') happens when use shortcut N in a task where first label has type "tag"
(<https://github.com/cvat-ai/cvat/pull/7997>)
11 changes: 10 additions & 1 deletion cvat-canvas/src/typescript/canvasModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel {
}

public draw(drawData: DrawData): void {
const supportedShapes = [
'rectangle', 'polygon', 'polyline', 'points', 'ellipse', 'cuboid', 'skeleton', 'mask',
];
if (![Mode.IDLE, Mode.DRAW].includes(this.data.mode)) {
throw Error(`Canvas is busy. Action: ${this.data.mode}`);
}
Expand All @@ -727,7 +730,13 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel {

if (!drawData.shapeType && !drawData.initialState) {
throw new Error('A shape type is not specified');
} else if (typeof drawData.numberOfPoints !== 'undefined') {
}

if (drawData.shapeType && !supportedShapes.includes(drawData.shapeType)) {
throw new Error(`Drawing method for type "${drawData.shapeType}" is not implemented`);
}

if (typeof drawData.numberOfPoints !== 'undefined') {
if (drawData.shapeType === 'polygon' && drawData.numberOfPoints < 3) {
throw new Error('A polygon consists of at least 3 points');
} else if (drawData.shapeType === 'polyline' && drawData.numberOfPoints < 2) {
Expand Down
16 changes: 12 additions & 4 deletions cvat-ui/src/reducers/annotation-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AuthActionTypes } from 'actions/auth-actions';
import { BoundariesActionTypes } from 'actions/boundaries-actions';
import { Canvas, CanvasMode } from 'cvat-canvas-wrapper';
import { Canvas3d } from 'cvat-canvas3d-wrapper';
import { DimensionType, JobStage } from 'cvat-core-wrapper';
import { DimensionType, JobStage, LabelType } from 'cvat-core-wrapper';
import { clamp } from 'utils/math';

import {
Expand Down Expand Up @@ -170,8 +170,16 @@ export default (state = defaultState, action: AnyAction): AnnotationState => {
const defaultLabel = job.labels.length ? job.labels[0] : null;
const isReview = job.stage === JobStage.VALIDATION;
let workspaceSelected = null;
let activeShapeType = defaultLabel && defaultLabel.type !== 'any' ?
defaultLabel.type : ShapeType.RECTANGLE;
let activeObjectType;
let activeShapeType;
if (defaultLabel?.type === LabelType.TAG) {
activeObjectType = ObjectType.TAG;
} else {
activeShapeType = defaultLabel && defaultLabel.type !== 'any' ?
defaultLabel.type : ShapeType.RECTANGLE;
activeObjectType = job.mode === 'interpolation' ? ObjectType.TRACK : ObjectType.SHAPE;
}

if (job.dimension === DimensionType.DIMENSION_2D) {
if (queryParameters.initialWorkspace !== Workspace.STANDARD3D) {
workspaceSelected = queryParameters.initialWorkspace;
Expand Down Expand Up @@ -225,7 +233,7 @@ export default (state = defaultState, action: AnyAction): AnnotationState => {
drawing: {
...state.drawing,
activeLabelID: defaultLabel ? defaultLabel.id : null,
activeObjectType: job.mode === 'interpolation' ? ObjectType.TRACK : ObjectType.SHAPE,
activeObjectType,
activeShapeType,
},
canvas: {
Expand Down

0 comments on commit 14b65ac

Please sign in to comment.