Fix T43785 crash with border select.
Naming here is slightly misleading. We have: * Number of elements (objects) that can be picked * Buffer size * Number of integers in buffer. Interestingly enough, bufsize in OpenGL (as far as I could find in examples on the web) and in most of the code refers to the latter and actual buffer size is only used whenever we do allocations on the heap. Added an extra defines here to make things a bit clearer: * MAXPICKELEMS refers to the number of objects that can be picked * MAXPICKBUF refers to the number of integers in the selection buffer Also made all buffers use MAXPICKBUF where some used MAXPICKBUF * 4. That means that some parts of blender will use less space for selection now. MAXPICKBUF is set to 10000 for 2500 object selection, which can be changed at any time, but I think 10000 integers on the stack touches the borders of uglyland anyway.
This commit is contained in:
parent
340b76b42c
commit
50e9868abe
Notes:
blender-bot
2023-12-02 05:23:41 +01:00
Referenced by issue #102487, Select Box Tool: Selecting more than 2500 objects when 2500 is selected changes the tool's behavior, deselecting everything Referenced by issue #43785, crash with border select (many objects) Referenced by issue blender/blender-manual#102485, Box selection, tool or B key, doesn't select more than 5K objects
|
@ -275,7 +275,8 @@ bool ED_view3d_autodist_depth(struct ARegion *ar, const int mval[2], int margin,
|
|||
bool ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2], int margin, float *depth);
|
||||
|
||||
/* select */
|
||||
#define MAXPICKBUF 10000
|
||||
#define MAXPICKELEMS 2500
|
||||
#define MAXPICKBUF (4 * MAXPICKELEMS)
|
||||
short view3d_opengl_select(struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const struct rcti *input, bool do_nearest);
|
||||
|
||||
/* view3d_select.c */
|
||||
|
|
|
@ -583,7 +583,7 @@ bool mouse_mball(bContext *C, const int mval[2], bool extend, bool deselect, boo
|
|||
MetaBall *mb = (MetaBall *)obedit->data;
|
||||
MetaElem *ml, *ml_act = NULL;
|
||||
int a, hits;
|
||||
unsigned int buffer[4 * MAXPICKBUF];
|
||||
unsigned int buffer[MAXPICKBUF];
|
||||
rcti rect;
|
||||
|
||||
view3d_set_viewcontext(C, &vc);
|
||||
|
|
|
@ -1345,7 +1345,7 @@ Base *ED_view3d_give_base_under_cursor(bContext *C, const int mval[2])
|
|||
{
|
||||
ViewContext vc;
|
||||
Base *basact = NULL;
|
||||
unsigned int buffer[4 * MAXPICKBUF];
|
||||
unsigned int buffer[MAXPICKBUF];
|
||||
int hits;
|
||||
bool do_nearest;
|
||||
|
||||
|
@ -1443,7 +1443,7 @@ static bool mouse_select(bContext *C, const int mval[2],
|
|||
}
|
||||
}
|
||||
else {
|
||||
unsigned int buffer[4 * MAXPICKBUF];
|
||||
unsigned int buffer[MAXPICKBUF];
|
||||
bool do_nearest;
|
||||
|
||||
/* if objects have posemode set, the bones are in the same selection buffer */
|
||||
|
@ -1876,7 +1876,7 @@ static int do_meta_box_select(ViewContext *vc, rcti *rect, bool select, bool ext
|
|||
MetaElem *ml;
|
||||
int a;
|
||||
|
||||
unsigned int buffer[4 * MAXPICKBUF];
|
||||
unsigned int buffer[MAXPICKBUF];
|
||||
short hits;
|
||||
|
||||
hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, rect, false);
|
||||
|
@ -1910,7 +1910,7 @@ static int do_armature_box_select(ViewContext *vc, rcti *rect, bool select, bool
|
|||
EditBone *ebone;
|
||||
int a;
|
||||
|
||||
unsigned int buffer[4 * MAXPICKBUF];
|
||||
unsigned int buffer[MAXPICKBUF];
|
||||
short hits;
|
||||
|
||||
hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, rect, false);
|
||||
|
@ -2006,8 +2006,8 @@ static int do_object_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, b
|
|||
}
|
||||
|
||||
/* selection buffer now has bones potentially too, so we add MAXPICKBUF */
|
||||
vbuffer = MEM_mallocN(4 * (totobj + MAXPICKBUF) * sizeof(unsigned int), "selection buffer");
|
||||
hits = view3d_opengl_select(vc, vbuffer, 4 * (totobj + MAXPICKBUF), rect, false);
|
||||
vbuffer = MEM_mallocN(4 * (totobj + MAXPICKELEMS) * sizeof(unsigned int), "selection buffer");
|
||||
hits = view3d_opengl_select(vc, vbuffer, 4 * (totobj + MAXPICKELEMS), rect, false);
|
||||
/*
|
||||
* LOGIC NOTES (theeth):
|
||||
* The buffer and ListBase have the same relative order, which makes the selection
|
||||
|
|
|
@ -1679,9 +1679,9 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, const int mval[2], fl
|
|||
mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
|
||||
|
||||
if (do_passes)
|
||||
GPU_select_begin(buffer, 64, &selrect, GPU_SELECT_NEAREST_FIRST_PASS, 0);
|
||||
GPU_select_begin(buffer, 16, &selrect, GPU_SELECT_NEAREST_FIRST_PASS, 0);
|
||||
else
|
||||
GPU_select_begin(buffer, 64, &selrect, GPU_SELECT_ALL, 0);
|
||||
GPU_select_begin(buffer, 16, &selrect, GPU_SELECT_ALL, 0);
|
||||
|
||||
/* do the drawing */
|
||||
if (v3d->twtype & V3D_MANIP_ROTATE) {
|
||||
|
@ -1696,7 +1696,7 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, const int mval[2], fl
|
|||
hits = GPU_select_end();
|
||||
|
||||
if (do_passes) {
|
||||
GPU_select_begin(buffer, 64, &selrect, GPU_SELECT_NEAREST_SECOND_PASS, hits);
|
||||
GPU_select_begin(buffer, 16, &selrect, GPU_SELECT_NEAREST_SECOND_PASS, hits);
|
||||
|
||||
/* do the drawing */
|
||||
if (v3d->twtype & V3D_MANIP_ROTATE) {
|
||||
|
|
|
@ -59,6 +59,7 @@ typedef struct GPUQueryState {
|
|||
bool use_gpu_select;
|
||||
/* cache on initialization */
|
||||
unsigned int *buffer;
|
||||
/* buffer size (stores number of integers, for actual size multiply by sizeof integer)*/
|
||||
unsigned int bufsize;
|
||||
/* mode of operation */
|
||||
char mode;
|
||||
|
@ -191,7 +192,9 @@ unsigned int GPU_select_end(void)
|
|||
glGetQueryObjectuivARB(g_query_state.queries[i], GL_QUERY_RESULT_ARB, &result);
|
||||
if (result > 0) {
|
||||
if (g_query_state.mode != GPU_SELECT_NEAREST_SECOND_PASS) {
|
||||
if (hits < g_query_state.bufsize) {
|
||||
int maxhits = g_query_state.bufsize / 4;
|
||||
|
||||
if (hits < maxhits) {
|
||||
g_query_state.buffer[hits * 4] = 1;
|
||||
g_query_state.buffer[hits * 4 + 1] = 0xFFFF;
|
||||
g_query_state.buffer[hits * 4 + 2] = 0xFFFF;
|
||||
|
|
Loading…
Reference in New Issue