diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-11-10 12:37:02 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-11-10 12:37:02 +0400 |
commit | f5c9f2c2530d21474f8e2ee5ea7dfdb483b7ba7d (patch) | |
tree | d6b59677bb6d71fef7697bec930e80c94dad98dc | |
parent | c9cd4d61ba4ed9ac8285ec991d14964c3e98dd3c (diff) |
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.
-rw-r--r-- | intern/cycles/blender/CCL_api.h | 6 | ||||
-rw-r--r-- | intern/cycles/blender/blender_python.cpp | 13 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_userdef.c | 2 |
3 files changed, 15 insertions, 6 deletions
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); } } diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 31a1360829e..13219ea133d 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -395,7 +395,7 @@ static EnumPropertyItem *rna_userdef_compute_device_itemf(bContext *UNUSED(C), P int a; if (devices) { - for (a = 0; devices[a].name; a++) { + for (a = 0; devices[a].identifier[0]; a++) { tmp.value = devices[a].value; tmp.identifier = devices[a].identifier; tmp.name = devices[a].name; |