Cleanup: remove bmesh-operator error code

The error codes could be used to look up messages from a table
of messages however this wasn't especially useful.

Now all calls to BMO_error_raise must inclue a message.
This commit is contained in:
Campbell Barton 2021-07-01 17:01:19 +10:00
parent 927456491a
commit aaa8ee1307
9 changed files with 33 additions and 70 deletions

View File

@ -26,43 +26,27 @@
/* Pushes an error onto the bmesh error stack.
* if msg is null, then the default message for the `errcode` is used. */
void BMO_error_raise(BMesh *bm, BMOperator *owner, int errcode, const char *msg);
void BMO_error_raise(BMesh *bm, BMOperator *owner, const char *msg) ATTR_NONNULL(1, 2, 3);
/* Gets the topmost error from the stack.
* returns error code or 0 if no error. */
int BMO_error_get(BMesh *bm, const char **msg, BMOperator **op);
bool BMO_error_get(BMesh *bm, const char **r_msg, BMOperator **r_op);
bool BMO_error_occurred(BMesh *bm);
/* Same as #BMO_error_get, only pops the error off the stack as well. */
int BMO_error_pop(BMesh *bm, const char **msg, BMOperator **op);
bool BMO_error_pop(BMesh *bm, const char **r_msg, BMOperator **r_op);
void BMO_error_clear(BMesh *bm);
/* This is meant for handling errors, like self-intersection test failures.
* it's dangerous to handle errors in general though, so disabled for now. */
/* Catches an error raised by the op pointed to by catchop.
* errorcode is either the errorcode, or BMERR_ALL for any
* error. */
/* Catches an error raised by the op pointed to by catchop. */
/* Not yet implemented. */
// int BMO_error_catch_op(BMesh *bm, BMOperator *catchop, int errorcode, char **msg);
// int BMO_error_catch_op(BMesh *bm, BMOperator *catchop, char **msg);
#define BM_ELEM_INDEX_VALIDATE(_bm, _msg_a, _msg_b) \
BM_mesh_elem_index_validate(_bm, __FILE__ ":" STRINGIFY(__LINE__), __func__, _msg_a, _msg_b)
/*------ error code defines -------*/
/** Error messages. */
enum {
BMERR_CONNECTVERT_FAILED = 1,
BMERR_DISSOLVEFACES_FAILED,
BMERR_INVALID_SELECTION,
BMERR_MESH_ERROR,
BMERR_CONVEX_HULL_FAILED,
BMERR_TOTAL,
};
/* BMESH_ASSERT */
#ifdef WITH_ASSERT_ABORT
# define _BMESH_DUMMY_ABORT abort

View File

@ -42,17 +42,6 @@ static int bmo_name_to_slotcode(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char
static int bmo_name_to_slotcode_check(BMOpSlot slot_args[BMO_OP_MAX_SLOTS],
const char *identifier);
static const char *bmo_error_messages[] = {
NULL,
N_("Could not connect vertices"),
N_("Could not dissolve faces"),
N_("Invalid selection"),
N_("Internal mesh error"),
N_("Convex hull failed"),
};
BLI_STATIC_ASSERT(ARRAY_SIZE(bmo_error_messages) == BMERR_TOTAL, "message mismatch");
/* operator slot type information - size of one element of the type given. */
const int BMO_OPSLOT_TYPEINFO[BMO_OP_SLOT_TOTAL_TYPES] = {
0, /* 0: BMO_OP_SLOT_SENTINEL */
@ -1562,7 +1551,6 @@ bool BMO_iter_map_value_bool(BMOIter *iter)
/* error system */
typedef struct BMOpError {
struct BMOpError *next, *prev;
int errorcode;
BMOperator *op;
const char *msg;
} BMOpError;
@ -1574,14 +1562,10 @@ void BMO_error_clear(BMesh *bm)
}
}
void BMO_error_raise(BMesh *bm, BMOperator *owner, int errcode, const char *msg)
void BMO_error_raise(BMesh *bm, BMOperator *owner, const char *msg)
{
BMOpError *err = MEM_callocN(sizeof(BMOpError), "bmop_error");
err->errorcode = errcode;
if (!msg) {
msg = bmo_error_messages[errcode];
}
err->msg = msg;
err->op = owner;
@ -1594,35 +1578,35 @@ bool BMO_error_occurred(BMesh *bm)
}
/* returns error code or 0 if no error */
int BMO_error_get(BMesh *bm, const char **msg, BMOperator **op)
bool BMO_error_get(BMesh *bm, const char **r_msg, BMOperator **r_op)
{
BMOpError *err = bm->errorstack.first;
if (!err) {
return 0;
if (err == NULL) {
return false;
}
if (msg) {
*msg = err->msg;
if (r_msg) {
*r_msg = err->msg;
}
if (op) {
*op = err->op;
if (r_op) {
*r_op = err->op;
}
return err->errorcode;
return true;
}
int BMO_error_pop(BMesh *bm, const char **msg, BMOperator **op)
bool BMO_error_pop(BMesh *bm, const char **msg, BMOperator **op)
{
int errorcode = BMO_error_get(bm, msg, op);
bool result = BMO_error_get(bm, msg, op);
if (errorcode) {
if (result) {
BMOpError *err = bm->errorstack.first;
BLI_remlink(&bm->errorstack, bm->errorstack.first);
MEM_freeN(err);
}
return errorcode;
return result;
}
#define NEXT_CHAR(fmt) ((fmt)[0] != 0 ? (fmt)[1] : 0)

View File

@ -50,7 +50,7 @@ void bmo_bisect_plane_exec(BMesh *bm, BMOperator *op)
BMO_slot_vec_get(op->slots_in, "plane_no", plane_no);
if (is_zero_v3(plane_no)) {
BMO_error_raise(bm, op, BMERR_MESH_ERROR, "Zero normal given");
BMO_error_raise(bm, op, "Zero normal given");
return;
}

View File

@ -576,13 +576,12 @@ void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op)
BM_mesh_edgeloops_calc_center(bm, &eloops);
if (count < 2) {
BMO_error_raise(bm, op, BMERR_INVALID_SELECTION, "Select at least two edge loops");
BMO_error_raise(bm, op, "Select at least two edge loops");
goto cleanup;
}
if (use_pairs && (count % 2)) {
BMO_error_raise(
bm, op, BMERR_INVALID_SELECTION, "Select an even number of loops to bridge pairs");
BMO_error_raise(bm, op, "Select an even number of loops to bridge pairs");
goto cleanup;
}
@ -596,8 +595,7 @@ void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op)
}
}
if (!match) {
BMO_error_raise(
bm, op, BMERR_INVALID_SELECTION, "Selected loops must have equal edge counts");
BMO_error_raise(bm, op, "Selected loops must have equal edge counts");
goto cleanup;
}
}

View File

@ -211,7 +211,7 @@ void bmo_connect_verts_exec(BMesh *bm, BMOperator *op)
/* connect faces */
while ((f = BLI_LINKSTACK_POP(faces))) {
if (bm_face_connect_verts(bm, f, check_degenerate) == -1) {
BMO_error_raise(bm, op, BMERR_CONNECTVERT_FAILED, NULL);
BMO_error_raise(bm, op, "Could not connect vertices");
}
}

View File

@ -184,7 +184,7 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op)
if (BMO_error_occurred(bm)) {
BMO_error_clear(bm);
BMO_error_raise(bm, op, BMERR_DISSOLVEFACES_FAILED, NULL);
BMO_error_raise(bm, op, "Could not dissolve faces");
goto cleanup;
}
@ -201,8 +201,7 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op)
faces = regions[i];
if (!faces[0]) {
BMO_error_raise(
bm, op, BMERR_DISSOLVEFACES_FAILED, "Could not find boundary of dissolve region");
BMO_error_raise(bm, op, "Could not find boundary of dissolve region");
goto cleanup;
}
@ -220,7 +219,7 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op)
totface_target -= tot - 1;
}
else {
BMO_error_raise(bm, op, BMERR_DISSOLVEFACES_FAILED, "Could not create merged face");
BMO_error_raise(bm, op, "Could not create merged face");
goto cleanup;
}

View File

@ -619,7 +619,6 @@ void bmo_grid_fill_exec(BMesh *bm, BMOperator *op)
* extract two 'rail' loops from a single edge loop, see T72075. */
BMO_error_raise(bm,
op,
BMERR_INVALID_SELECTION,
"Select two edge loops "
"or a single closed edge loop from which two edge loops can be calculated");
goto cleanup;
@ -634,7 +633,7 @@ void bmo_grid_fill_exec(BMesh *bm, BMOperator *op)
v_b_last = ((LinkData *)BM_edgeloop_verts_get(estore_b)->last)->data;
if (BM_edgeloop_is_closed(estore_a) || BM_edgeloop_is_closed(estore_b)) {
BMO_error_raise(bm, op, BMERR_INVALID_SELECTION, "Closed loops unsupported");
BMO_error_raise(bm, op, "Closed loops unsupported");
goto cleanup;
}
@ -672,8 +671,7 @@ void bmo_grid_fill_exec(BMesh *bm, BMOperator *op)
bm_edgeloop_flag_set(estore_b, BM_ELEM_HIDDEN, false);
if (BLI_listbase_is_empty(&eloops_rail)) {
BMO_error_raise(
bm, op, BMERR_INVALID_SELECTION, "Loops are not connected by wire/boundary edges");
BMO_error_raise(bm, op, "Loops are not connected by wire/boundary edges");
goto cleanup;
}
@ -681,7 +679,7 @@ void bmo_grid_fill_exec(BMesh *bm, BMOperator *op)
BLI_assert(v_a_last != v_b_last);
if (BM_edgeloop_overlap_check(estore_rail_a, estore_rail_b)) {
BMO_error_raise(bm, op, BMERR_INVALID_SELECTION, "Connecting edge loops overlap");
BMO_error_raise(bm, op, "Connecting edge loops overlap");
goto cleanup;
}

View File

@ -554,7 +554,7 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op)
/* Verify that at least three verts in the input */
if (!hull_num_input_verts_is_ok(op)) {
BMO_error_raise(bm, op, BMERR_CONVEX_HULL_FAILED, "Requires at least three vertices");
BMO_error_raise(bm, op, "Requires at least three vertices");
return;
}

View File

@ -1143,7 +1143,7 @@ void bmo_subdivide_edgering_exec(BMesh *bm, BMOperator *op)
count = BM_mesh_edgeloops_find(bm, &eloops_rim, bm_edge_rim_test_cb, (void *)bm);
if (count < 2) {
BMO_error_raise(bm, op, BMERR_INVALID_SELECTION, "No edge rings found");
BMO_error_raise(bm, op, "No edge rings found");
goto cleanup;
}
else if (count == 2) {
@ -1167,7 +1167,7 @@ void bmo_subdivide_edgering_exec(BMesh *bm, BMOperator *op)
changed = true;
}
else {
BMO_error_raise(bm, op, BMERR_INVALID_SELECTION, "Edge-ring pair isn't connected");
BMO_error_raise(bm, op, "Edge-ring pair isn't connected");
goto cleanup;
}
}
@ -1179,7 +1179,7 @@ void bmo_subdivide_edgering_exec(BMesh *bm, BMOperator *op)
LoopPairStore **lpair_arr;
if (eloop_pairs_gs == NULL) {
BMO_error_raise(bm, op, BMERR_INVALID_SELECTION, "Edge-rings are not connected");
BMO_error_raise(bm, op, "Edge-rings are not connected");
goto cleanup;
}