Problem with obj.destroy()

Oct 19, 2013 at 4:53 PM
First of all, great engine!
I am using sheetengine for a multiplayer game, for the characters I'm using the example provided in "collision detection".
Now everything works great, you control your user, and see other users moving when they move. But I have a problem when they leave.
All users online are stored in the client on an array as follows:
App.players[data.user] // where data.user is their (unique) name
When a user disconnects, I'm doing:
Which seems to work for everyone except for the first user that was online, who sees this message after:
Uncaught TypeError: Cannot read property 'hidden' of undefined
If you need any more info let me know
Oct 19, 2013 at 6:33 PM
Is it possible to send me over a short example where the problem can be reproduced?
Also: does it also happen when using "calculateChangedSheets" or only with "calculateAllSheets"?
Oct 19, 2013 at 6:43 PM
You solved it!
Changing calculateAllSheets to calculateChangedSheets fixed the problem,

In case you want to take a look, the source code can be found in

The files that are relevant are:

public/assets/js/app.js:108 (Character destroyed)
public/assets/js/open-rpg/character-open-rpg.js (Here the character is created)

Oct 19, 2013 at 6:47 PM
I might have replied too fast, using calculateChangedSheets solves it temporarily.

As soon as I call calculateAllSheets again the problem reappears. Any ideas?
Oct 19, 2013 at 6:53 PM
Ok after some testing, if I only use calculateChangedSheets when moving characters it works fine.

At the moment I don't need to call calculateAllSheets, it works just fine as is. In what case should I call calculateAllSheets?
Oct 19, 2013 at 7:09 PM
The difference between the two methods is that calculateAllSheets "forgets" all data and recalculates everything from the ground up, whereas calculateChangedSheets only calculates the changes to the previous state. For example if you move an object that gets behind some sheets then the latter function would recalculate the object's sheets and also recalculate the sheets that are in interaction with the changed object, in this case the sheets that occlude the object after moving. Therefore normally you never need to call calculateAllSheets, and calculateChangedSheets is much faster.

This is what I wrote in the documentation:
"Depending on the number of sheets needed to be recalculated one or the other method could perform better. Typically we will use calculateAllSheets to calculate initial scenes and then use calculateChangedSheets in every iteration later on to calculate the changes."

It might happen there is some sort of bug in calculateAllSheets regarding deleted sheets, I will try to reproduce the issue.
Oct 19, 2013 at 7:14 PM
That's what I was thinking, and if I extend the original scene adding basesheets I can still call calculateChangedSheets?

At the moment I'm calling calculateAllSheets only when rendering initially the scene. But the plan is for the map to grow dynamically on the client
Oct 19, 2013 at 7:41 PM
Yes, you could still call calculateChangedSheets in that case as well. If you load large number of sheets/basesheets it could happen that performance drops and it would be better to use the other function, but this is something for you to test and check.
Oct 19, 2013 at 7:57 PM
Great, if I find the problem with calculateAllSheets I will let you know. The game is running at, but at the moment the error is no longer happening, except very rare cases.
I don't know exactly what triggers it so I can't reproduce it always