Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2018-01-22 14:54:00 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2018-01-22 14:54:00 +0300
commita3616980c6e6491faa726090a47c89b1ab2119a4 (patch)
tree3afc5bda04ca52b2c566106688f40d7e0dc30d99
parent2f6d7946a4a6b44e99a133f58f43c463a70fc317 (diff)
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().
-rw-r--r--intern/cycles/blender/addon/properties.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index 68474529ed3..ec9f93671d8 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -1366,37 +1366,49 @@ 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 = []
+ def update_device_entries(self, device_list):
for device in device_list:
if not device[1] in {'CUDA', 'OPENCL'}:
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)
# Create new entry if no existing one was found
if not entry:
entry = self.devices.add()
entry.id = device[2]
entry.name = device[0]
entry.type = device[1]
+ elif entry.name != device[0]:
+ # 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 = []
+ 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)
- return cuda_devices, opencl_devices
+ return cuda_devices, opencl_devices
def get_num_gpu_devices(self):
import _cycles