Fix T81520: Crash setting the Cycles device from Python

This commit is contained in:
Campbell Barton 2020-10-15 16:51:18 +11:00
parent 4bea4702d5
commit 1001adb500
Notes: blender-bot 2023-02-14 06:00:50 +01:00
Referenced by issue #81877, Crash using get_devices_for_type() to choose cycles device with python
Referenced by issue #81806, Error getting Cycles GPU devices if device_type is set to NONE
Referenced by issue #81520, Crash when choosing cycles device with python
Referenced by issue #77348, Blender LTS: Maintenance Task 2.83
1 changed files with 6 additions and 1 deletions

View File

@ -1608,8 +1608,13 @@ class CyclesPreferences(bpy.types.AddonPreferences):
# For backwards compatibility, only returns CUDA and OpenCL but still
# refreshes all devices.
def get_devices(self, compute_device_type=''):
import _cycles
# Ensure `self.devices` is not re-allocated when the second call to
# get_devices_for_type is made, freeing items from the first list.
for device_type in ('CUDA', 'OPTIX', 'OPENCL'):
self.update_device_entries(_cycles.available_devices(device_type))
cuda_devices = self.get_devices_for_type('CUDA')
self.get_devices_for_type('OPTIX')
opencl_devices = self.get_devices_for_type('OPENCL')
return cuda_devices, opencl_devices