Skip to content

Fix Cannot read properties of undefined (reading 'occluded')#10853

Open
klakhov wants to merge 3 commits into
developfrom
kl/fix-mask-occluded
Open

Fix Cannot read properties of undefined (reading 'occluded')#10853
klakhov wants to merge 3 commits into
developfrom
kl/fix-mask-occluded

Conversation

@klakhov

@klakhov klakhov commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Motivation and context

Fixes a crash when placing a pasted mask if the brush toolset is reconfigured while the paste is still in progress:

Cannot read properties of undefined (reading 'occluded')

Reproduction:

  1. Create a mask and finish it.
  2. Copy it (start a paste).
  3. Press the brush tool in the toolbar before clicking to place the mask.
  4. Click on the canvas to place it.

Root cause: pasting a mask starts the insertion pipeline in MasksHandlerImpl.draw(), which sets isInsertion = true and stores this.drawData (containing initialState). While that insertion is still live, the brush toolset legitimately re-issues canvasInstance.draw({ enabled: true, shapeType: 'mask', ... }) on brush size/tool changes but without initialState. That second call fell through to the drawing branch and unconditionally ran this.drawData = drawData, wiping out initialState while isInsertion stayed true. The next mouse:down then read this.drawData.initialState.occluded on undefined and threw.

This only affects masks because they are the only shape whose toolset reconfigures the active draw() mid-insertion; insertion also reports as Mode.DRAW, so only the canvas (which owns the private isInsertion flag) can distinguish a paste from a fresh draw. The fix therefore lives in cvat-canvas and makes draw() robust to reconfiguration calls during an active insertion:

  • capture whether an insertion was already running before the call,
  • skip the brush/drawing pipeline init while inserting,
  • preserve the insertion's drawData (and its initialState) until the insertion actually ends.

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues

License

  • I submit my code changes under the same MIT License that covers the project.

@klakhov klakhov requested a review from bsekachev as a code owner July 1, 2026 08:42
@klakhov klakhov requested a review from nmanovic as a code owner July 1, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant