[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40275] branches/soc-2011-onion-uv-tools/ source/blender/editors/uvedit/uvedit_ops.c: Make code more bulletproof by detecting allocation failures.

Antony Riakiotakis kalast at gmail.com
Fri Sep 16 22:20:02 CEST 2011


Revision: 40275
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40275
Author:   psy-fi
Date:     2011-09-16 20:20:01 +0000 (Fri, 16 Sep 2011)
Log Message:
-----------
Make code more bulletproof by detecting allocation failures.

Modified Paths:
--------------
    branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c

Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c	2011-09-16 20:08:05 UTC (rev 40274)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c	2011-09-16 20:20:01 UTC (rev 40275)
@@ -2316,6 +2316,10 @@
 			preview->previewUnstitchable = (float *)MEM_mallocN(preview->numOfUnstitchable*sizeof(float)*4, "stitch_preview_unstichable_data");
 		}
 
+		if(!preview->previewQuads || !preview->previewTris || !preview->previewStitchable || !preview->previewUnstitchable){
+			return 0;
+		}
+
 		if(state->mode == VERT_STITCH){
 			/* Fill the preview buffers with stitchable only faces */
 			for(i = 0; i < state->numOfSeparateUvs; i++){
@@ -2523,7 +2527,10 @@
 		}
 	}
 
-	stitch_process_data(stitch_state, 0, 1);
+	if(!stitch_process_data(stitch_state, 0, 1)){
+		stitch_state_delete(stitch_state);
+		return 0;
+	}
 
 	stitch_update_header(stitch_state, C);
 	return 1;
@@ -2542,7 +2549,7 @@
 	return OPERATOR_RUNNING_MODAL;
 }
 
-static void stitch_exit(bContext *C, wmOperator *op)
+static void stitch_exit(bContext *C, wmOperator *op, int finished)
 {
 	StitchState *stitch_state;
 	Scene *scene;
@@ -2556,15 +2563,18 @@
 
 	stitch_state = (StitchState *)op->customdata;
 
-	RNA_float_set(op->ptr, "limit", stitch_state->limitDist);
-	RNA_boolean_set(op->ptr, "use_limit", stitch_state->use_limit);
-	RNA_boolean_set(op->ptr, "snap_islands", stitch_state->snapIslands);
-	RNA_enum_set(op->ptr, "mode", stitch_state->mode);
+	if(finished){
+		RNA_float_set(op->ptr, "limit", stitch_state->limitDist);
+		RNA_boolean_set(op->ptr, "use_limit", stitch_state->use_limit);
+		RNA_boolean_set(op->ptr, "snap_islands", stitch_state->snapIslands);
+		RNA_enum_set(op->ptr, "mode", stitch_state->mode);
 
+		uvedit_live_unwrap_update(sima, scene, obedit);
+	}
+
 	if(sa)
 		ED_area_headerprint(sa, NULL);
 
-	uvedit_live_unwrap_update(sima, scene, obedit);
 	DAG_id_tag_update(obedit->data, 0);
 	WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 	BKE_mesh_end_editmesh(obedit->data, stitch_state->em);
@@ -2576,14 +2586,23 @@
 }
 
 
+static int stitch_cancel(bContext *C, wmOperator *op)
+{
+	stitch_exit(C, op, 0);
+	return OPERATOR_CANCELLED;
+}
+
+
 static int stitch_exec(bContext *C, wmOperator *op)
 {
-	int returnValue;
 	if(!stitch_init(C, op))
 		return OPERATOR_CANCELLED;
-	returnValue = stitch_process_data((StitchState *)op->customdata, 1, 1);
-	stitch_exit(C, op);
-	return returnValue;
+	if(stitch_process_data((StitchState *)op->customdata, 1, 1)){
+		stitch_exit(C, op, 1);
+		return OPERATOR_FINISHED;
+	}else {
+		return stitch_cancel(C, op);
+	}
 }
 
 static int stitch_modal(bContext *C, wmOperator *op, wmEvent *event)
@@ -2603,28 +2622,28 @@
 		/* Cancel */
 		case ESCKEY:
 		case RIGHTMOUSE:
-			stitch_exit(C, op);
-			return OPERATOR_CANCELLED;
+			return stitch_cancel(C, op);
 
+
 		case LEFTMOUSE:
 		case PADENTER:
-		case RETKEY:{
-			int returnValue;
-			returnValue = stitch_process_data(stitch_state, 1, 1);
-			stitch_exit(C, op);
-			if(returnValue){
+		case RETKEY:
+			if(stitch_process_data(stitch_state, 1, 1)){
+				stitch_exit(C, op, 1);
 				return OPERATOR_FINISHED;
 			}
 			else {
-				return OPERATOR_CANCELLED;
+				return stitch_cancel(C, op);
 			}
-		}
+
 		/* Increase limit */
 		case PADPLUSKEY:
 		case WHEELUPMOUSE:
 			if(event->ctrl){
 				stitch_state->limitDist += 0.01;
-				stitch_process_data(stitch_state, 0, 1);
+				if(!stitch_process_data(stitch_state, 0, 1)){
+					return stitch_cancel(C, op);
+				}
 				break;
 			}
 			else{
@@ -2636,7 +2655,9 @@
 			if(event->ctrl){
 				stitch_state->limitDist -= 0.01;
 				stitch_state->limitDist = MAX2(0.01, stitch_state->limitDist);
-				stitch_process_data(stitch_state, 0, 1);
+				if(!stitch_process_data(stitch_state, 0, 1)){
+					return stitch_cancel(C, op);
+				}
 				break;
 			}else{
 				return OPERATOR_PASS_THROUGH;
@@ -2646,7 +2667,9 @@
 		case LKEY:
 			if(event->val == KM_PRESS){
 				stitch_state->use_limit = !stitch_state->use_limit;
-				stitch_process_data(stitch_state, 0, 1);
+				if(!stitch_process_data(stitch_state, 0, 1)){
+					return stitch_cancel(C, op);
+				}
 				break;
 			}
 			return OPERATOR_RUNNING_MODAL;
@@ -2659,7 +2682,9 @@
 				else
 					stitch_state->mode = EDGE_STITCH;
 
-				stitch_process_data(stitch_state, 0, 1);
+				if(!stitch_process_data(stitch_state, 0, 1)){
+					return stitch_cancel(C, op);
+				}
 				break;
 			}
 			return OPERATOR_RUNNING_MODAL;
@@ -2796,7 +2821,9 @@
 						}
 					}
 				}
-				stitch_process_data(stitch_state, 0, 0);
+				if(!stitch_process_data(stitch_state, 0, 0)){
+					return stitch_cancel(C, op);
+				}
 				break;
 			}
 			return OPERATOR_RUNNING_MODAL;
@@ -2814,7 +2841,9 @@
 		case SKEY:
 			if(event->val == KM_PRESS){
 				stitch_state->snapIslands = !stitch_state->snapIslands;
-				stitch_process_data(stitch_state, 0, 1);
+				if(!stitch_process_data(stitch_state, 0, 1)){
+					return stitch_cancel(C, op);
+				}
 				break;
 			} else
 			return OPERATOR_RUNNING_MODAL;
@@ -2829,12 +2858,6 @@
 	return OPERATOR_RUNNING_MODAL;
 }
 
-static int stitch_cancel(bContext *C, wmOperator *op)
-{
-	stitch_exit(C, op);
-	return OPERATOR_CANCELLED;
-}
-
 static void UV_OT_stitch(wmOperatorType *ot)
 {
 	static EnumPropertyItem mode[] = {




More information about the Bf-blender-cvs mailing list