# HG changeset patch # User Thinker K.F. Li # Date 1302083558 -28800 # Node ID c60a978f98b1dad46b28179afc2fde51b5745912 # Parent f34d2fcbcd0de3833d5e017232230be8adb2a6d0 Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree(). It caused by _xnjsmb_coord_clone_from_subtree_mod() does not create an JS wrapper object every descendants of the subtree. We do not provide any method for traveling tree. So, it is fine to clone a subtree without creating wrapper objects for descendants. So, we check if an object own a JS wrapper object before invalidating it. diff -r f34d2fcbcd0d -r c60a978f98b1 nodejs/coord.cc --- a/nodejs/coord.cc Wed Apr 06 15:13:09 2011 +0800 +++ b/nodejs/coord.cc Wed Apr 06 17:52:38 2011 +0800 @@ -81,6 +81,14 @@ FOR_COORDS_PREORDER(coord, child) { child_hdl = (Persistent *)mb_prop_get(&child->obj.props, PROP_JSOBJ); + /* There is no associated JS object. Perhaps, it is created + * by xnjsmb_coord_clone_from_subtree(). + */ + if(child_hdl == NULL) { + preorder_coord_skip_subtree(child); + continue; + } + SET(*child_hdl, "valid", _false); WRAP(*child_hdl, NULL); child_hdl->Dispose(); @@ -90,6 +98,12 @@ FOR_COORD_SHAPES(child, mem) { mem_hdl = (Persistent *)mb_prop_get(&mem->obj.props, PROP_JSOBJ); + /* There is no associated JS object. Perhaps, it is + * created by xnjsmb_coord_clone_from_subtree(). + */ + if(mem_hdl == NULL) + continue; + SET(*mem_hdl, "valid", _false); WRAP(*mem_hdl, NULL); mem_hdl->Dispose(); @@ -236,9 +250,20 @@ _xnjsmb_coord_clone_from_subtree_mod(Handle src, Handle ret) { Handle js_rt; Handle ret_obj = ret->ToObject(); + coord_t *ret_coord, *child; + Handle child_obj; js_rt = GET(src, "mbrt")->ToObject(); SET(ret_obj, "mbrt", js_rt); + + /* Only root of the subtree is warpped. Descendants of subtree + * are not wrapped by JS object. We have no any method to access + * children and members of a coord, now. So, it is fine. But, + * sometime later, we will provide APIs for traveling a tree. At + * that time, we need to create wrappers for all descendants. + */ + ret_coord = (coord_t *)UNWRAP(ret_obj); + xnjsmb_coord_mod(ret_obj, ret_coord); } static coord_t * @@ -257,6 +282,7 @@ *err = "can not clone a subtree (allocate memory)"; return NULL; } + rdman_coord_changed(rdman, cloning); return cloning; }