Strange script bug

Strange script bug

c is the container, i is an item

It should remove the item, but it does not.

However it works without modifying anything even if you commit.

(It is extracted from a bigger script, perhaps the save is not necessary)

LL.save();

c.getProperties().edit().setEventHandler(“i.tap”,EventHandler.UNSET,null).commit();//doesn’t work

//c.getProperties().edit().commit();//does work

c.removeItem(i);

LL.save();

]]>

3 Commentsto Strange script bug

  1. Anonymous says:

    < ![CDATA[

    I think this could be because i is assigned before commit. Commit will trigger a reload of the container so that changes are taken into account. As a consequence the reference on the item i is not valid anymore. This would explain that edit().commit() works, because there is no change hence no reload. Re-getting the item by its id after the commit should work.


    The fact that the container is reloaded is not documented. And even though it would be properly documented, I admit that the fact that references may become invalid isn’t obvious.


    Maybe it could be possible to introduce an internal weak reference which would be dynamically resolved when the item is accessed, I’ll have a look at this.

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Oh, never thought of that.


    Yes, taking the item again works.


    Now I know it I won’t need that reference fix, but I see it will be useful in other cases, even for scripts that animate an item.



    I also discovered another ‘bug’, if you remove the LL.save() before commit, changes made from script are not saved, or at least strange things happens. (Didn’t took the time to test all changes, but I guess that the sample without the LL.save() triggers it)

    ]]>

  3. Anonymous says:

    < ![CDATA[

    LL.save() may save some item that would be reloaded because of a container change.


    This is a caveat (that could probably be fixed by saving the container when needed before to run the commit…).

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *