[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57474] trunk/blender/source/blender/gpu/ intern/gpu_draw.c: Fix #35768: crash in with "free image textures" option and 3D viewport with textured

Brecht Van Lommel brechtvanlommel at pandora.be
Sat Jun 15 16:01:16 CEST 2013


Revision: 57474
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57474
Author:   blendix
Date:     2013-06-15 14:01:16 +0000 (Sat, 15 Jun 2013)
Log Message:
-----------
Fix #35768: crash in with "free image textures" option and 3D viewport with textured
draw mode open. OpenGL texture free needs to happen in the main thread, but it was
freeing a copy of the image datablock. I can't understand how this code ever worked,
probably it never did.

Modified Paths:
--------------
    trunk/blender/source/blender/gpu/intern/gpu_draw.c

Modified: trunk/blender/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_draw.c	2013-06-15 14:01:12 UTC (rev 57473)
+++ trunk/blender/source/blender/gpu/intern/gpu_draw.c	2013-06-15 14:01:16 UTC (rev 57474)
@@ -34,7 +34,10 @@
 
 #include "GL/glew.h"
 
+#include "BLI_blenlib.h"
+#include "BLI_linklist.h"
 #include "BLI_math.h"
+#include "BLI_threads.h"
 #include "BLI_utildefines.h"
 
 #include "DNA_lamp_types.h"
@@ -52,9 +55,6 @@
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
-#include "BLI_threads.h"
-#include "BLI_blenlib.h"
-
 #include "BKE_bmfont.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
@@ -1123,19 +1123,18 @@
 #endif // WITH_SMOKE
 }
 
-static ListBase image_free_queue = {NULL, NULL};
+static LinkNode *image_free_queue = NULL;
 
 static void gpu_queue_image_for_free(Image *ima)
 {
-	Image *cpy = MEM_dupallocN(ima);
-
 	BLI_lock_thread(LOCK_OPENGL);
-	BLI_addtail(&image_free_queue, cpy);
+	BLI_linklist_append(&image_free_queue, ima);
 	BLI_unlock_thread(LOCK_OPENGL);
 }
 
 void GPU_free_unused_buffers(void)
 {
+	LinkNode *node;
 	Image *ima;
 
 	if (!BLI_thread_is_main())
@@ -1144,11 +1143,17 @@
 	BLI_lock_thread(LOCK_OPENGL);
 
 	/* images */
-	for (ima=image_free_queue.first; ima; ima=ima->id.next)
-		GPU_free_image(ima);
+	for (node=image_free_queue; node; node=node->next) {
+		ima = node->link;
 
-	BLI_freelistN(&image_free_queue);
+		/* check in case it was freed in the meantime */
+		if (BLI_findindex(&G.main->image, ima) != -1)
+			GPU_free_image(ima);
+	}
 
+	BLI_linklist_free(image_free_queue, NULL);
+	image_free_queue = NULL;
+
 	/* vbo buffers */
 	/* it's probably not necessary to free all buffers every frame */
 	/* GPU_buffer_pool_free_unused(0); */




More information about the Bf-blender-cvs mailing list