AirSim icon indicating copy to clipboard operation
AirSim copied to clipboard

There is mistake coding in SetSegmentationId API.

Open ykpgrr opened this issue 7 years ago • 0 comments

Hi, When I use SetSegmentationID API from python client with using client.simSetSegmentationID with Regex=True, Python is freezing. I tracked the code and I found it: AirSim/Unity/UnityDemo/Assets/AirSimAssets/Scripts/HUD/CameraFiltersScript.cs The SetSegmentationId function is wrong. It try to iterate over the dictionary and also try to set a value in same dictionary. This is wrong for C#. Please look at the: Editing Dictionary Values in a foreach loop

The original code is:

        public static bool SetSegmentationId(string objectName, int segmentationId, bool isNameRegex) { 
            if (isNameRegex) {isNameRegex
                bool isValueSet = false;
                foreach (string s in segmentationIds.Keys) {
                    if (!s.Contains(objectName)) {
                        continue;
                    }
                    segmentationIds[objectName] = segmentationId;
                    isValueSet = true;
                }
                return isValueSet;
            }

The code should be like that:

        public static bool SetSegmentationId(string objectName, int segmentationId, bool isNameRegex) {
            List<string> keyList = new List<string>(segmentationIds.Keys); // new added
            if (isNameRegex) {
                bool isValueSet = false;
                foreach (string s in keyList) {  // iterate over list. Not the dictionary
                    if (!s.Contains(objectName)) {
                        continue;
                    }
                    segmentationIds[objectName] = segmentationId;
                    isValueSet = true;
                }
                return isValueSet;
            }
  • OS: Linux and Windows *AirSim version: 1.2 Python version: 3.6.5

ykpgrr avatar Jan 25 '19 07:01 ykpgrr