From f5c9f2c2530d21474f8e2ee5ea7dfdb483b7ba7d Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sat, 10 Nov 2012 08:37:02 +0000 Subject: Cycles: correction to how device of lists is exposed to blender compute_device_list is using static vector of device information which had pointers (identifier and name) to values from device information structures. That structures are also stored in static vector and being refreshed every 5 seconds. The issue is, as soon as device information is being updated, pointers in vector from compute_device_list became incorrect. Seems it was the reason of issues with sudden switching from CUDA to OpenCL on my desktop and from CUDA to CPU on my laptop, It was also seems to be making persistent images behaves instable. Made it so device identifier and name are copied from device info to structures used by RNA (CCLDeviceInfo). Alternative could be avoid cacheing CCLDeviceInfo and always use actual list of device information by RNA. It shouldn't be so much slow. --- intern/cycles/blender/CCL_api.h | 6 +++--- intern/cycles/blender/blender_python.cpp | 13 +++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'intern/cycles/blender') diff --git a/intern/cycles/blender/CCL_api.h b/intern/cycles/blender/CCL_api.h index 469d63d1530..b8a30b71717 100644 --- a/intern/cycles/blender/CCL_api.h +++ b/intern/cycles/blender/CCL_api.h @@ -23,12 +23,12 @@ extern "C" { #endif -/* returns a list of devices for selection, array is name NULL pointer +/* returns a list of devices for selection, array is empty identifier * terminated and must not be freed */ typedef struct CCLDeviceInfo { - const char *identifier; - const char *name; + char identifier[128]; + char name[512]; int value; } CCLDeviceInfo; diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp index e78c78e5eb2..d164920ceff 100644 --- a/intern/cycles/blender/blender_python.cpp +++ b/intern/cycles/blender/blender_python.cpp @@ -418,14 +418,23 @@ static CCLDeviceInfo *compute_device_list(DeviceType type) if(info.type == type || (info.type == DEVICE_MULTI && info.multi_devices[0].type == type)) { - CCLDeviceInfo cinfo = {info.id.c_str(), info.description.c_str(), i++}; + CCLDeviceInfo cinfo; + + strncpy(cinfo.identifier, info.id.c_str(), sizeof(cinfo.identifier)); + cinfo.identifier[info.id.length()] = '\0'; + + strncpy(cinfo.name, info.description.c_str(), sizeof(cinfo.name)); + cinfo.name[info.description.length()] = '\0'; + + cinfo.value = i++; + device_list.push_back(cinfo); } } /* null terminate */ if(!device_list.empty()) { - CCLDeviceInfo cinfo = {NULL, NULL, 0}; + CCLDeviceInfo cinfo = {"", "", 0}; device_list.push_back(cinfo); } } -- cgit v1.2.3