Index: lua.cpp
===================================================================
--- lua.cpp	(revision 5392)
+++ lua.cpp	(working copy)
@@ -8447,11 +8447,20 @@
 	int bound_rc, pof;
 	int modelnum;
 
+	bool not_in_frame = !(g3_in_frame() > 0);
+
+	if( not_in_frame ) {
+		g3_start_frame(0);
+	}
+
 	switch ( targetp->type ) {
 		case OBJ_SHIP:
 			modelnum = Ship_info[Ships[targetp->instance].ship_info_index].model_num;
 			bound_rc = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
 			if ( bound_rc != 0 ) {
+				if( not_in_frame ) {
+					g3_end_frame();
+				}
 				return ADE_RETURN_NIL;
 			}
 			break;
@@ -8459,6 +8468,9 @@
 			modelnum = Debris[targetp->instance].model_num;
 			bound_rc = submodel_find_2d_bound_min( modelnum, Debris[targetp->instance].submodel_num, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
 			if ( bound_rc != 0 ) {
+				if( not_in_frame ) {
+					g3_end_frame();
+				}
 				return ADE_RETURN_NIL;
 			}
 			break;
@@ -8487,15 +8499,11 @@
 	y1 -= padding;
 	y2 += padding;
 	if ( draw_box ) {
-		if( !(g3_in_frame() > 0) ) {
-			g3_start_frame(0);
-			draw_brackets_square(x1, y1, x2, y2, false);
-			g3_end_frame();
-		}
-		else {
-			draw_brackets_square(x1, y1, x2, y2, false);
-		}
+		draw_brackets_square(x1, y1, x2, y2, false);
 	}
+	if( not_in_frame ) {
+		g3_end_frame();
+	}
 
 	return ade_set_args(L, "iiii", x1, y1, x2, y2);
 }
