KineticJS icon indicating copy to clipboard operation
KineticJS copied to clipboard

this.getParent() is undefined

Open stewartl60 opened this issue 14 years ago • 12 comments

The latest build is throwing the following JS Error:

TypeError: this.getParent() is undefined

/**

  • get layer ancestor
  • @name getLayer
  • @methodOf Kinetic.Node.prototype */ getLayer: function() { return this.getParent().getLayer(); },

The steps to reproduce this on, create a draggable layer where on endDrag you are clearing out the contents and redrawing. After dragging far enough in any direction, these errors start to blow up.

stewartl60 avatar Nov 30 '12 01:11 stewartl60

Follow up to this one, the error is actually triggered on the mouseout event, after meeting the above conditions:

element.on('mouseout', function(){ //do something here this.getLayer().draw(); });

this.getLayer() throws the error

stewartl60 avatar Nov 30 '12 01:11 stewartl60

I am getting a similar issue.

Fix would be great, thanks.

charlesbodman avatar Nov 30 '12 01:11 charlesbodman

hi I need more info. Can you post a jsfiddle demonstrating the behavior? Thanks!

ericdrowell avatar Nov 30 '12 02:11 ericdrowell

Here is a js fiddle of the error http://jsfiddle.net/m2sUr/3/

Unfortunately, inside js fiddle, the click event does not fire (not sure why) so please view it here --> http://jsfiddle.net/m2sUr/3/embedded/result/

I'll try and get more info on why this is happening a bit later

danshultz avatar Nov 30 '12 22:11 danshultz

As an aside, if I get into the nextTick by wrapping a setTimeout around the remove, things are fine.


setTimeout(function () {
  square.remove();
}, 0);

danshultz avatar Nov 30 '12 22:11 danshultz

yea, looks like a context problem inside the on() method. I'll add this to my todo list. Thanks!!

ericdrowell avatar Dec 01 '12 02:12 ericdrowell

Unfortunatelly got the same issue, when object "looses" its parent inside .transitionTo method. Had to rollback to v4.0.5

P.S. Happens only on "concurrent" runs. I.e. if I run another transitionTo before previous has been done.

dkulagin avatar Dec 06 '12 14:12 dkulagin

fixed! The problem was that the drag and drop module still had a reference to the node that was removed which caused things to blow (in other words, this problem only occurred if your shape was draggable:true). Here's the change:

https://github.com/ericdrowell/KineticJS/commit/5e16b3d7d0538dce04d35a91acebc288918be51c

ericdrowell avatar Dec 13 '12 08:12 ericdrowell

Proposed fix did not solve the issue, same error as before.

stewartl60 avatar Dec 14 '12 19:12 stewartl60

it fixed the jsfiddle mentioned in the issue:

http://jsfiddle.net/9YfSc/

if there are other conditions where the problem occurs, can you create a new ticket?

ericdrowell avatar Dec 15 '12 02:12 ericdrowell

I am getting the exact issue @mrgoodcat has described "if I run another transitionTo before previous has been done." with v4.2.0

eddielee6 avatar Dec 30 '12 23:12 eddielee6

I am getting the this.getParent() undefined error message. I am deleting an array with groups(having shapes) and shapes(line, rect etc) as its elements. Individual shapes are getting deleted but the error occurs if there is any one group inside that array. Thanks !!!

ashokpd avatar Dec 18 '13 05:12 ashokpd