WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Bug in vizproximity.Manager.removeSensor (https://forum.worldviz.com/showthread.php?t=4969)

fordprefect 03-04-2014 10:08 AM

Bug in vizproximity.Manager.removeSensor
 
When moving our code from using hotspots to vizproximity I seem to have discovered a bug in this module (both already available in Vizard4). The method vizproximity.Manager.getActiveSensors() can return sensors which have already been deleted through vizproximity.Manager.removeSensor(). Which, when you have the need to add and remove frequently, leads to accumulation of (not available) sensors in the active list of a target.

I took the liberty to check the module and found this: the update routine adds a set of sensors that are currently triggered to each target and stores this in the self._target dictionary:
Code:

        def update(self):
                """Update state of proximity sensors and trigger enter/exit events if needed"""

                # Don't bother checking if no targets or sensors
                if not (self._targets and self._sensors):
                        return

                # Set of active sensors for debugging purposes
                activeSensors = None
                if self._debugRoot is not None:
                        activeSensors = set()

                # Check if each target is in range of each sensor
                events = []
                for t,active in self._targets.iteritems():                        pos = t.getPosition()
                        for s in self._sensors.iterkeys():
                                isInside = s.containsPoint(pos)
                                if isInside and activeSensors is not None:
                                        activeSensors.add(s)
                                wasInside = s in active
                                if wasInside != isInside:
                                        if isInside:
                                                active.add(s)
                                                events.append( (ENTER_PROXIMITY_EVENT, ProximityEvent(s,t,self)) )
                                        else:
                                                active.remove(s)
                                                events.append( (EXIT_PROXIMITY_EVENT, ProximityEvent(s,t,self)) )
                :
                :

Unfortunately, when a sensor is deleted, this set of active sensors at each target is not updated. The code highlighted does correct the problem (get in touch about my fee, please :D)
Code:

        def removeSensor(self,sensor):
                """Remove a proximity sensor from the manager"""
                try:
                        data = self._sensors[sensor]
                except KeyError:
                        return

                # Remove debug node of sensor
                if data.debug:
                        data.debug.remove()

                # Remove sensor from target's active list (C) Siemens AG
                for active in self._targets.itervalues():
                        active.discard(sensor)

                # Remove sensor from dictionary
                del self._sensors[sensor]
                sensor.removeRemoveCallback(self.removeSensor)

Hope this helps to make the Vizard5 release even better! ;)

Jeff 03-18-2014 11:50 PM

Thanks for taking the time to report this bug and also find a fix!

mape2k 11-07-2014 01:04 AM

Could you please include this fix in a future release of both 4 and 5? I have multiple machines on which I run Vizard and I don't want to fix this error on all of them...

Thanks!

fordprefect 11-10-2014 12:48 AM

As far as I have checked, the patch is included in the final release of Vizard5.
If Vizard4 will receive another patch - I don't think so. But that's up to WorldViz, of course.

Best Regards, Walter


All times are GMT -7. The time now is 04:32 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC