Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deep cloning stackoverflow #3421

Closed
Rad1calDreamer opened this issue Nov 15, 2016 · 13 comments · Fixed by #3434
Closed

deep cloning stackoverflow #3421

Rad1calDreamer opened this issue Nov 15, 2016 · 13 comments · Fixed by #3434

Comments

@Rad1calDreamer
Copy link

if object have shadow, fabric.util.object.extend call stackpverflow error
#3262

Version

1.6.7

@asturur
Copy link
Member

asturur commented Nov 15, 2016

can i ask you a fiddle?
fabric.util.object.extend is not meant to clone a fabricObject, for that you use Rect.clone() or Line.clone().

fabric.util.object.extend extends js objects, like {a:1, b:4}

@asturur
Copy link
Member

asturur commented Nov 15, 2016

@eschnabel

@Rad1calDreamer
Copy link
Author

@asturur i dont understand why this dont reproduce in fiddle
http://jsfiddle.net/pyvxcsup/30/

@Rad1calDreamer
Copy link
Author

my console
image

@asturur
Copy link
Member

asturur commented Nov 15, 2016

Can we replicate with some code?

this.canvas.forEachObject(function(obj) {
            if (!obj.id) {
               var _obj2 = obj.toObject(['x1', 'y1', 'x2', 'y2', 'objID', 'selectable']),
                  _obj;
               if (obj.type === 'path') {
                  _obj = new fabric.Path.fromObject(_obj2, function(foo) {
                        _tmpCanvas.add(foo);
                     }
                  );
               } else {
                  _obj =
                     new fabric [fabric.util.string.camelize(fabric.util.string.capitalize(obj.type))].fromObject(_obj2);
                  _tmpCanvas.add(_obj);
               }

            }
         });

On kitchensink with 1.6.7 i can clone objects and restore from json objects with shadows with no problem.

Where are you using the clone function in the code provided?

@Rad1calDreamer
Copy link
Author

i need create png image of my canvas, excluding object with id, to make illusion of freedraw under objects.
I create static canvas, add all of objects i needed, and create which i append in canvas container

@asturur
Copy link
Member

asturur commented Nov 15, 2016

Can you just replicate a situation in wich calling extend or clone is gonna fail?

@Rad1calDreamer
Copy link
Author

call Stack for crash
image

@asturur
Copy link
Member

asturur commented Nov 15, 2016

i need to see what is inside source var.
Can you make it on a fiddle? Is there any technical stop to replicate the problem and isolate it?

@Rad1calDreamer
Copy link
Author

while i try create fiddle, send one more screenshort
image

@asturur
Copy link
Member

asturur commented Nov 15, 2016

ok i can stop you now.
That extend with deep cannot clone functions.
I guess that is why you get the error.
Is an internal tool to clone stuff like styles and properties. Has problems with functions.
I can detect if there is a function and just send the reference of it.
Better than error anyway. I think you should use something like lodash if you need a deep clone function that works always.

@Rad1calDreamer
Copy link
Author

i add hasOwnProperty in "for in" to "fix" this

@asturur
Copy link
Member

asturur commented Nov 15, 2016

fix the error but is gonna change the function result.
Do you think you can make up a fiddle with the error? can you make the error appear with plain fabric and some code?

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 a pull request may close this issue.

2 participants