diff options
-rw-r--r-- | source/blender/editors/mesh/editmesh_bisect.c | 6 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c | 16 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 4 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_types.h | 10 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_gesture.c | 6 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_window.c | 12 |
6 files changed, 37 insertions, 17 deletions
diff --git a/source/blender/editors/mesh/editmesh_bisect.c b/source/blender/editors/mesh/editmesh_bisect.c index bc60ff9274f..1d173d8e396 100644 --- a/source/blender/editors/mesh/editmesh_bisect.c +++ b/source/blender/editors/mesh/editmesh_bisect.c @@ -148,7 +148,7 @@ static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event) BisectData *opdata; opdata = MEM_mallocN(sizeof(BisectData), "inset_operator_data"); - gesture->userdata = opdata; + gesture->user_data.data = opdata; opdata->backup_len = objects_len; opdata->backup = MEM_callocN(sizeof(*opdata->backup) * objects_len, __func__); @@ -193,7 +193,7 @@ static void edbm_bisect_exit(bContext *C, BisectData *opdata) static int mesh_bisect_modal(bContext *C, wmOperator *op, const wmEvent *event) { wmGesture *gesture = op->customdata; - BisectData *opdata = gesture->userdata; + BisectData *opdata = gesture->user_data.data; BisectData opdata_back = *opdata; /* annoyance, WM_gesture_straightline_modal, frees */ int ret; @@ -276,7 +276,7 @@ static int mesh_bisect_exec(bContext *C, wmOperator *op) } wmGesture *gesture = op->customdata; - BisectData *opdata = (gesture != NULL) ? gesture->userdata : NULL; + BisectData *opdata = (gesture != NULL) ? gesture->user_data.data : NULL; /* -------------------------------------------------------------------- */ /* Modal support */ diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c index c904bf2005b..b6a6c897606 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c @@ -695,7 +695,7 @@ static void gradientVertInit__mapFunc(void *userData, static int paint_weight_gradient_modal(bContext *C, wmOperator *op, const wmEvent *event) { wmGesture *gesture = op->customdata; - WPGradient_vertStoreBase *vert_cache = gesture->userdata; + WPGradient_vertStoreBase *vert_cache = gesture->user_data.data; int ret = WM_gesture_straightline_modal(C, op, event); if (ret & OPERATOR_RUNNING_MODAL) { @@ -751,15 +751,15 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) WPGradient_userData data = {NULL}; if (is_interactive) { - if (gesture->userdata == NULL) { - gesture->userdata = MEM_mallocN(sizeof(WPGradient_vertStoreBase) + - (sizeof(WPGradient_vertStore) * me->totvert), - __func__); - gesture->userdata_free = false; + if (gesture->user_data.data == NULL) { + gesture->user_data.data = MEM_mallocN(sizeof(WPGradient_vertStoreBase) + + (sizeof(WPGradient_vertStore) * me->totvert), + __func__); + gesture->user_data.use_free = false; data.is_init = true; wpaint_prev_create( - &((WPGradient_vertStoreBase *)gesture->userdata)->wpp, me->dvert, me->totvert); + &((WPGradient_vertStoreBase *)gesture->user_data.data)->wpp, me->dvert, me->totvert); /* on init only, convert face -> vert sel */ if (me->editflag & ME_EDIT_PAINT_FACE_SEL) { @@ -767,7 +767,7 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) } } - vert_cache = gesture->userdata; + vert_cache = gesture->user_data.data; } else { if (ED_wpaint_ensure_data(C, op->reports, 0, NULL) == false) { diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 70f986732ad..346996285a4 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -67,6 +67,7 @@ struct wmMsgSubscribeValue; struct wmOperator; struct wmOperatorType; struct wmPaintCursor; +struct wmGenericUserData; #ifdef WITH_INPUT_NDOF struct wmNDOFMotionData; @@ -795,6 +796,9 @@ void WM_tooltip_init(struct bContext *C, struct wmWindow *win); void WM_tooltip_refresh(struct bContext *C, struct wmWindow *win); double WM_tooltip_time_closed(void); +/* wmGenericUserData */ +void WM_generic_user_data_free(struct wmGenericUserData *user_data); + #ifdef __cplusplus } #endif diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index b3c36857dce..d2e71496494 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -120,6 +120,13 @@ struct wmWindowManager; /* Include external gizmo API's */ #include "gizmo/WM_gizmo_api.h" +typedef struct wmGenericUserData { + void *data; + /** When NULL, use #MEM_freeN. */ + void (*free_fn)(void *data); + bool use_free; +} wmGenericUserData; + /* ************** wmOperatorType ************************ */ /* flag */ @@ -442,8 +449,7 @@ typedef struct wmGesture { /* customdata for straight line is a recti: (xmin,ymin) is start, (xmax, ymax) is end */ /* free pointer to use for operator allocs (if set, its freed on exit)*/ - void *userdata; - bool userdata_free; + wmGenericUserData user_data; } wmGesture; /* ************** wmEvent ************************ */ diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index b12bb89ea9f..e117a1bcdfe 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -62,7 +62,7 @@ wmGesture *WM_gesture_new(bContext *C, const wmEvent *event, int type) gesture->type = type; gesture->event_type = event->type; gesture->winrct = ar->winrct; - gesture->userdata_free = true; /* Free if userdata is set. */ + gesture->user_data.use_free = true; /* Free if userdata is set. */ gesture->modal_state = GESTURE_MODAL_NOP; if (ELEM(type, @@ -106,9 +106,7 @@ void WM_gesture_end(bContext *C, wmGesture *gesture) } BLI_remlink(&win->gesture, gesture); MEM_freeN(gesture->customdata); - if (gesture->userdata && gesture->userdata_free) { - MEM_freeN(gesture->userdata); - } + WM_generic_user_data_free(&gesture->user_data); MEM_freeN(gesture); } diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 7ae572e5685..0f93a03da6b 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -2290,3 +2290,15 @@ void WM_opengl_context_release(void *context) BLI_assert(GPU_framebuffer_active_get() == NULL); GHOST_ReleaseOpenGLContext((GHOST_ContextHandle)context); } + +void WM_generic_user_data_free(wmGenericUserData *wm_userdata) +{ + if (wm_userdata->data && wm_userdata->use_free) { + if (wm_userdata->free_fn) { + wm_userdata->free_fn(wm_userdata->data); + } + else { + MEM_freeN(wm_userdata->data); + } + } +} |