[Bf-blender-cvs] [2c347ebbba9] blender2.8: Fix T57874: Crash due to IMM_BUFFER_SIZE when drawing cached frames...

Clément Foucault noreply at git.blender.org
Fri Nov 16 19:26:52 CET 2018


Commit: 2c347ebbba9b76c26f3a4b1e4f8bbe84cb90d1f4
Author: Clément Foucault
Date:   Fri Nov 16 19:26:23 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB2c347ebbba9b76c26f3a4b1e4f8bbe84cb90d1f4

Fix T57874: Crash due to IMM_BUFFER_SIZE when drawing cached frames...

... in the timeline.

===================================================================

M	source/blender/editors/space_action/action_draw.c
M	source/blender/gpu/GPU_immediate_util.h
M	source/blender/gpu/intern/gpu_immediate_util.c

===================================================================

diff --git a/source/blender/editors/space_action/action_draw.c b/source/blender/editors/space_action/action_draw.c
index 77def4af6d0..738c5e4d2e2 100644
--- a/source/blender/editors/space_action/action_draw.c
+++ b/source/blender/editors/space_action/action_draw.c
@@ -476,7 +476,6 @@ void timeline_draw_cache(SpaceAction *saction, Object *ob, Scene *scene)
 		}
 
 		const int sta = pid->cache->startframe, end = pid->cache->endframe;
-		const int len = (end - sta + 1) * 6;
 
 		GPU_blend(true);
 
@@ -493,23 +492,40 @@ void timeline_draw_cache(SpaceAction *saction, Object *ob, Scene *scene)
 
 		immUniformColor4fv(col);
 
-		if (len > 0) {
-			immBeginAtMost(GPU_PRIM_TRIS, len);
+		{
+			/* draw a quad for each chunk of consecutive cached frames */
+			const int chunk_tot = 32;
+			int chunk_len = 0;
+			int ista = 0, iend = -1;
 
-			/* draw a quad for each cached frame */
 			for (int i = sta; i <= end; i++) {
 				if (pid->cache->cached_frames[i - sta]) {
-					immVertex2f(pos, (float)i - 0.5f, 0.0f);
-					immVertex2f(pos, (float)i - 0.5f, 1.0f);
-					immVertex2f(pos, (float)i + 0.5f, 1.0f);
-
-					immVertex2f(pos, (float)i - 0.5f, 0.0f);
-					immVertex2f(pos, (float)i + 0.5f, 1.0f);
-					immVertex2f(pos, (float)i + 0.5f, 0.0f);
+					if (chunk_len == 0) {
+						immBeginAtMost(GPU_PRIM_TRIS, chunk_tot * 6);
+					}
+					if (ista > iend) {
+						chunk_len++;
+						ista = i;
+					}
+					iend = i;
+				}
+				else {
+					if (ista <= iend) {
+						immRectf_fast(pos, (float)ista - 0.5f, 0.0f, (float)iend + 0.5f, 1.0f);
+						iend = ista - 1;
+					}
+					if (chunk_len >= chunk_tot) {
+						immEnd();
+						chunk_len = 0;
+					}
 				}
 			}
-
-			immEnd();
+			if (ista <= iend) {
+				immRectf_fast(pos, (float)ista - 0.5f, 0.0f, (float)iend + 0.5f, 1.0f);
+			}
+			if (chunk_len != 0) {
+				immEnd();
+			}
 		}
 
 		GPU_blend(false);
diff --git a/source/blender/gpu/GPU_immediate_util.h b/source/blender/gpu/GPU_immediate_util.h
index 7baf359c52e..e5b259b4783 100644
--- a/source/blender/gpu/GPU_immediate_util.h
+++ b/source/blender/gpu/GPU_immediate_util.h
@@ -33,6 +33,7 @@ void immRectf(uint pos, float x1, float y1, float x2, float y2);
 void immRecti(uint pos, int x1, int y1, int x2, int y2);
 
 /* Same as immRectf/immRecti but does not call immBegin/immEnd. To use with GPU_PRIM_TRIS. */
+void immRectf_fast(uint pos, float x1, float y1, float x2, float y2);
 void immRectf_fast_with_color(uint pos, uint col, float x1, float y1, float x2, float y2, const float color[4]);
 void immRecti_fast_with_color(uint pos, uint col, int x1, int y1, int x2, int y2, const float color[4]);
 
diff --git a/source/blender/gpu/intern/gpu_immediate_util.c b/source/blender/gpu/intern/gpu_immediate_util.c
index 983c70281a2..5cba0c42ee3 100644
--- a/source/blender/gpu/intern/gpu_immediate_util.c
+++ b/source/blender/gpu/intern/gpu_immediate_util.c
@@ -87,6 +87,17 @@ void immRecti(uint pos, int x1, int y1, int x2, int y2)
 	immEnd();
 }
 
+void immRectf_fast(uint pos, float x1, float y1, float x2, float y2)
+{
+	immVertex2f(pos, x1, y1);
+	immVertex2f(pos, x2, y1);
+	immVertex2f(pos, x2, y2);
+
+	immVertex2f(pos, x1, y1);
+	immVertex2f(pos, x2, y2);
+	immVertex2f(pos, x1, y2);
+}
+
 void immRectf_fast_with_color(uint pos, uint col, float x1, float y1, float x2, float y2, const float color[4])
 {
 	immAttr4fv(col, color);



More information about the Bf-blender-cvs mailing list