PDA

View Full Version : Random RuntimeError


sleiN13
10-30-2013, 07:24 AM
I don't know when but probably while removing an Avatar from the world I get a RuntimeError.

Traceback (most recent call last):
File "C:\Program Files (x86)\WorldViz\Vizard4\python\viz.py", line 2581, in _RemoveObject
obj.__class__._OnRemoveObject(obj)
File "C:\Program Files (x86)\WorldViz\Vizard4\python\viz.py", line 5750, in _OnRemoveObject
VizBone._RemoveAvatarBones(obj)
File "C:\Program Files (x86)\WorldViz\Vizard4\python\viz.py", line 5968, in _RemoveAvatarBones
bones = [ id for id in cls._VizObjectCache.iterkeys() if begin <= id < end ]
RuntimeError: dictionary changed size during iteration

It seems the _VizObjectCache is changed during the remove operation, I'm loading avatars using the "viztask.schedule" and "yield viztask.waitDirector" because loading the avatar and initializing my code around it would take to long causing jutters in the framerate.

Could this be the cause? and how could i solve it?

JvdBosch
10-31-2013, 12:27 AM
You could try preloading all models. For another project with a lot of avatars, I just preload one and clone() that one when I need a new one. That is instant.

Using the director is tricky...

sleiN13
10-31-2013, 07:22 AM
I'm already preloading the avatars, but I still need to initialize the code around the avatar, this involves creating some additional helper object on the avatar together with some other time consuming code. In all it takes between 5 to 7 ms to construct an avatar making loading even 1 avatar per frame noticeable. Using the director method it take 70 ms but the framerate is influenced a lot less. I assumed the async methods of Vizard would work well with Vizard?

farshizzo
10-31-2013, 08:20 AM
Most Vizard commands are not thread safe, especially when it comes to adding/removing objects from different threads. The viz.director function mainly exists for backwards compatibility reasons, and is only intended to be used to perform non-Vizard related operations (e.g. file/socket IO).

Having said that, loading models in director threads can work. You just need to be very careful not to add/remove other models while the asynchronous operation is being performed. Additionally, the model should be added to a dummy scene when being loaded asynchronously, to avoid adding the model while the active scene is rendering.

Vizard 5 will have built-in support to load models/avatars asynchronously, and all the threading issues will be handled automatically.

sleiN13
11-01-2013, 04:00 AM
When i want to load the model in a different scene how can I set the scene of the object back to viz.MainScene? There doesn't seem to be a setScene function on Node3D objects.

farshizzo
11-01-2013, 11:46 AM
The node.setParent command can be used to reparent a node to another scene:node.setParent(viz.WORLD, viz.MainScene)

sleiN13
11-04-2013, 12:45 AM
When setting the parent do all the children of the node you re-parent also get transferred to the new scene?

And adding children to a node that is in a different scene do they get automatically relinked to that scene?

farshizzo
11-05-2013, 09:10 AM
Yes, when you set the parent of the node, all children of that node will be moved to the new scene.