[Bf-blender-cvs] [ab1af38c74a] master: Cycles: Fix crash opening user preferences after adding extra GPU

Sergey Sharybin noreply at git.blender.org
Tue Dec 19 15:52:42 CET 2017


Commit: ab1af38c74a5f20115e14fdd54d7580df380a924
Author: Sergey Sharybin
Date:   Tue Dec 19 15:51:28 2017 +0100
Branches: master
https://developer.blender.org/rBab1af38c74a5f20115e14fdd54d7580df380a924

Cycles: Fix crash opening user preferences after adding extra GPU

We can not store pointers to elements of collection property in the
case we modify that collection. This is like storing pointers to
elements of array before calling realloc().

===================================================================

M	intern/cycles/blender/addon/properties.py

===================================================================

diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index b17593a19d6..7d1cbadce1b 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -1371,24 +1371,19 @@ class CyclesPreferences(bpy.types.AddonPreferences):
 
     devices = bpy.props.CollectionProperty(type=CyclesDeviceSettings)
 
-    def get_devices(self):
-        import _cycles
-        # Layout of the device tuples: (Name, Type, Persistent ID)
-        device_list = _cycles.available_devices()
+    def find_existing_device_entry(self, device):
+        for device_entry in self.devices:
+            if device_entry.id == device[2] and device_entry.type == device[1]:
+                return device_entry
+        return None
 
-        cuda_devices = []
-        opencl_devices = []
-        cpu_devices = []
+
+    def update_device_entries(self, device_list):
         for device in device_list:
             if not device[1] in {'CUDA', 'OPENCL', 'CPU'}:
                 continue
-
-            entry = None
             # Try to find existing Device entry
-            for dev in self.devices:
-                if dev.id == device[2] and dev.type == device[1]:
-                    entry = dev
-                    break
+            entry = self.find_existing_device_entry(device)
             if not entry:
                 # Create new entry if no existing one was found
                 entry = self.devices.add()
@@ -1400,17 +1395,30 @@ class CyclesPreferences(bpy.types.AddonPreferences):
                 # Update name in case it changed
                 entry.name = device[0]
 
-            # Sort entries into lists
+
+    def get_devices(self):
+        import _cycles
+        # Layout of the device tuples: (Name, Type, Persistent ID)
+        device_list = _cycles.available_devices()
+        # Make sure device entries are up to date and not referenced before
+        # we know we don't add new devices. This way we guarantee to not
+        # hold pointers to a resized array.
+        self.update_device_entries(device_list)
+        # Sort entries into lists
+        cuda_devices = []
+        opencl_devices = []
+        cpu_devices = []
+        for device in device_list:
+            entry = self.find_existing_device_entry(device)
             if entry.type == 'CUDA':
                 cuda_devices.append(entry)
             elif entry.type == 'OPENCL':
                 opencl_devices.append(entry)
-            else:
+            elif entry.type == 'CPU':
                 cpu_devices.append(entry)
-
+        # Extend all GPU devices with CPU.
         cuda_devices.extend(cpu_devices)
         opencl_devices.extend(cpu_devices)
-
         return cuda_devices, opencl_devices



More information about the Bf-blender-cvs mailing list