Cycles: Fix crash changing image after recent OpenCL changes
Steps to reproduce: - Create shader Image texture -> Diffuse BSDF -> Output. Do NOT select image yet! - Start viewport render. - Select image from the ID browser of Image Texture node. Thing is: with the memory manager we always need to inform device that memory was freed.
This commit is contained in:
parent
0e57282999
commit
f2809ae0a6
|
@ -716,12 +716,7 @@ void ImageManager::device_load_image(Device *device,
|
|||
if(dscene->tex_float4_image[slot] == NULL)
|
||||
dscene->tex_float4_image[slot] = new device_vector<float4>();
|
||||
device_vector<float4>& tex_img = *dscene->tex_float4_image[slot];
|
||||
|
||||
if(tex_img.device_pointer) {
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
device->tex_free(tex_img);
|
||||
}
|
||||
|
||||
device_tex_free_safe(device, tex_img);
|
||||
if(!file_load_image<TypeDesc::FLOAT, float>(img,
|
||||
type,
|
||||
texture_limit,
|
||||
|
@ -748,12 +743,7 @@ void ImageManager::device_load_image(Device *device,
|
|||
if(dscene->tex_float_image[slot] == NULL)
|
||||
dscene->tex_float_image[slot] = new device_vector<float>();
|
||||
device_vector<float>& tex_img = *dscene->tex_float_image[slot];
|
||||
|
||||
if(tex_img.device_pointer) {
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
device->tex_free(tex_img);
|
||||
}
|
||||
|
||||
device_tex_free_safe(device, tex_img);
|
||||
if(!file_load_image<TypeDesc::FLOAT, float>(img,
|
||||
type,
|
||||
texture_limit,
|
||||
|
@ -777,12 +767,7 @@ void ImageManager::device_load_image(Device *device,
|
|||
if(dscene->tex_byte4_image[slot] == NULL)
|
||||
dscene->tex_byte4_image[slot] = new device_vector<uchar4>();
|
||||
device_vector<uchar4>& tex_img = *dscene->tex_byte4_image[slot];
|
||||
|
||||
if(tex_img.device_pointer) {
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
device->tex_free(tex_img);
|
||||
}
|
||||
|
||||
device_tex_free_safe(device, tex_img);
|
||||
if(!file_load_image<TypeDesc::UINT8, uchar>(img,
|
||||
type,
|
||||
texture_limit,
|
||||
|
@ -809,12 +794,7 @@ void ImageManager::device_load_image(Device *device,
|
|||
if(dscene->tex_byte_image[slot] == NULL)
|
||||
dscene->tex_byte_image[slot] = new device_vector<uchar>();
|
||||
device_vector<uchar>& tex_img = *dscene->tex_byte_image[slot];
|
||||
|
||||
if(tex_img.device_pointer) {
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
device->tex_free(tex_img);
|
||||
}
|
||||
|
||||
device_tex_free_safe(device, tex_img);
|
||||
if(!file_load_image<TypeDesc::UINT8, uchar>(img,
|
||||
type,
|
||||
texture_limit,
|
||||
|
@ -837,12 +817,7 @@ void ImageManager::device_load_image(Device *device,
|
|||
if(dscene->tex_half4_image[slot] == NULL)
|
||||
dscene->tex_half4_image[slot] = new device_vector<half4>();
|
||||
device_vector<half4>& tex_img = *dscene->tex_half4_image[slot];
|
||||
|
||||
if(tex_img.device_pointer) {
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
device->tex_free(tex_img);
|
||||
}
|
||||
|
||||
device_tex_free_safe(device, tex_img);
|
||||
if(!file_load_image<TypeDesc::HALF, half>(img,
|
||||
type,
|
||||
texture_limit,
|
||||
|
@ -868,12 +843,7 @@ void ImageManager::device_load_image(Device *device,
|
|||
if(dscene->tex_half_image[slot] == NULL)
|
||||
dscene->tex_half_image[slot] = new device_vector<half>();
|
||||
device_vector<half>& tex_img = *dscene->tex_half_image[slot];
|
||||
|
||||
if(tex_img.device_pointer) {
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
device->tex_free(tex_img);
|
||||
}
|
||||
|
||||
device_tex_free_safe(device, tex_img);
|
||||
if(!file_load_image<TypeDesc::HALF, half>(img,
|
||||
type,
|
||||
texture_limit,
|
||||
|
@ -957,11 +927,7 @@ void ImageManager::device_free_image(Device *device, DeviceScene *dscene, ImageD
|
|||
tex_img = NULL;
|
||||
}
|
||||
if(tex_img) {
|
||||
if(tex_img->device_pointer) {
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
device->tex_free(*tex_img);
|
||||
}
|
||||
|
||||
device_tex_free_safe(device, *tex_img);
|
||||
delete tex_img;
|
||||
}
|
||||
}
|
||||
|
@ -1097,5 +1063,16 @@ void ImageManager::device_free(Device *device, DeviceScene *dscene)
|
|||
dscene->tex_half_image.clear();
|
||||
}
|
||||
|
||||
void ImageManager::device_tex_free_safe(Device *device, device_memory& mem)
|
||||
{
|
||||
if(mem.device_pointer) {
|
||||
thread_scoped_lock device_lock(device_mutex);
|
||||
device->tex_free(mem);
|
||||
}
|
||||
else {
|
||||
device->tex_free(mem);
|
||||
}
|
||||
}
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
||||
|
|
|
@ -160,6 +160,11 @@ private:
|
|||
DeviceScene *dscene,
|
||||
ImageDataType type,
|
||||
int slot);
|
||||
|
||||
/* Will do locking when needed and make sure possible memory manager from
|
||||
* the device implementation is aware of freed texture.
|
||||
*/
|
||||
void device_tex_free_safe(Device *device, device_memory& mem);
|
||||
};
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
|
Loading…
Reference in New Issue