Fix related to #32929: update list of available devices for cycles rendering
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 22 Oct 2012 14:04:44 +0000 (14:04 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 22 Oct 2012 14:04:44 +0000 (14:04 +0000)
while Blender is running, not only on load. It might help a case when Blender
is started before the CUDA driver is fully initialized.

intern/cycles/device/device.cpp
intern/cycles/util/util_task.h

index 9a4d364a9b8e42133a2145f112c85cffe2b398de..5d3f23d954a4ecd9abde77a3a604e81baa16f5d1 100644 (file)
@@ -28,6 +28,7 @@
 #include "util_math.h"
 #include "util_opencl.h"
 #include "util_opengl.h"
+#include "util_time.h"
 #include "util_types.h"
 #include "util_vector.h"
 
@@ -188,6 +189,18 @@ vector<DeviceInfo>& Device::available_devices()
 {
        static vector<DeviceInfo> devices;
        static bool devices_init = false;
+       static double device_update_time = 0.0;
+
+       /* only update device list if we're not actively rendering already, things
+        * could go very wrong if a device suddenly becomes (un)available. also do
+        * it only every 5 seconds. it not super cpu intensive but don't want to do
+        * it on every redraw. */
+       if(devices_init) {
+               if(!TaskScheduler::active() && (time_dt() > device_update_time + 5.0)) {
+                       devices.clear();
+                       devices_init = false;
+               }
+       }
 
        if(!devices_init) {
 #ifdef WITH_CUDA
@@ -211,6 +224,7 @@ vector<DeviceInfo>& Device::available_devices()
 #endif
 
                devices_init = true;
+               device_update_time = time_dt();
        }
 
        return devices;
index 401a503f5401dae80bc5b26c1592562dcfb76b4d..a2f284479c77e3bb5e56eb609a9e3ba4b5185c3c 100644 (file)
@@ -95,6 +95,7 @@ public:
        static void exit();
 
        static int num_threads() { return threads.size(); }
+       static bool active() { return users != 0; }
 
 protected:
        friend class TaskPool;