Fabric.js: Cannot read property 'bringToFront' of undefined

Created on 2 Jan 2020  路  9Comments  路  Source: fabricjs/fabric.js

There seems to be cases where bringToFront can be called when this.canvas is undefined. It's tricky to reproduce, but it seems like this.canvas just needs an existence check before bringToFront is called. Let me know if you think this should be fixed on my end.

Thanks!

image

bug

All 9 comments

I wonder how. I m ok with a safeguard, but i also would like to figure out how you got there.
There may be a real bug somewhere else

I have it in a mouse:down listener, so I wonder if i'm removing the canvas and the listener is still firing after that

    fabricCanvas.on('mouse:down', options => {
      if (fabricCanvas.isDrawingMode) this.setControlsVisibility(false);

      // Bring to front on click if not drawing
      if (!fabricCanvas.isDrawingMode && options.target && options.target.__corner === 0) options.target.bringToFront();
    });

Well it does not look like you are removing the canvas. Is strange that the canvas is not there.

I am doing some very non-typical things with it though, where the canvas is used during certain steps of our recording flow, and then is removed during playback. You can see what I'm doing here - https://kinetoscope.flipgrid.com/

Fabric powers all of the drawing and sticker management on the recording step.

Yes so probably in the process of moving an object from a canvas to another something is off.

(anyway the bring to front on click is an embedded feature called preserveObjectStacking i m not sure if is something that is usefull for you that avoid the custom code).

i'm ok with adding a else if (this.canvas) {
I'm also ok to remove the feature later completely, since the idea of having the same functionality on both canvas and objects, seems to be bad on the long run.

As a dev calling bringToFront of an object and having it reuse either the canvas function to bring it up, or the same function but called with the group as context ( so that is brought top in the group stack ) seems just a magical confusion.

As today, as opposed as me of 4 years ago, i would just kill that method completely.

Good to know about preserveObjectStacking and thanks as always for your prompt responses!

if you have time for adding the guarding if, please open a pr.

PR opened, sorry for the delay!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amancqlsys picture amancqlsys  路  5Comments

zhangzhzh picture zhangzhzh  路  4Comments

eugene-g13 picture eugene-g13  路  3Comments

bevacqua picture bevacqua  路  4Comments

semiadam picture semiadam  路  3Comments