Page MenuHome

[2.8 Crash] Program crash when extruding+face snap
Closed, ResolvedPublic

Description

System Information
win 7 x64
Nvidia 1070 (Gigabyte G1) Drivers: 398.36

Blender Version
Broken: Hash: 66a00b64c5c (date: 2018-07-29 02:12)

Short description of error
Crashes when extruding.
The windows console prints this error after crash

Exact steps for others to reproduce the error
1-Open


2- Select an edge of the "RETOPO" object
3- use E to extrude.
4-if doesn't crash try a few times.

[Demo Video]
I know that video its not the way to report bugs but i wasn't able to get an example to properly crash first try, the crashes in the video are lucky first try crashes.
https://www.youtube.com/watch?v=lyjg734Tg2o

Event Timeline

Bastien Montagne (mont29) triaged this task as Incomplete priority.Jul 31 2018, 10:10 AM

Hmmm… Tried like 20 times, could not get a single crash…

Please:

  • Try the latest build from our buildbot.
  • Try to start Blender in factory settings (--factory-startup commandline option) (this will ensure whether this is a userpref or addon issue or not).
  • Launch Blender from the command line with -t 1 option (single thread mode).
  • Launch Blender from the command line with -d option and attach as text file here any error printed out in the console (do not paste it directly in comment).
  • Launch Blender from the command line with --debug-gpu option and attach as text file here any error printed out in the console (do not paste it directly in comment).
s12a (s12a) added a subscriber: s12a (s12a).EditedJul 31 2018, 10:22 AM

After extruding an edge 3 times with E, I could reproduce the issue on 5300ba0ba50 and:
Windows 10 Pro 64 bit (1803)
AMD Radeon RX480 4GB with Radeon Software 18.7.1

I used a debug build, here's the backtrace.


Bastien Montagne (mont29) raised the priority of this task from Incomplete to Normal.Jul 31 2018, 3:50 PM

@Germano Cavalcante (mano-wii) looks like crash happens in raycasting code, maybe you are interested in investigating that one? Especially since it seems to only be reproducible on windows. :/

In summary the problem is in the update_mesh_edit_mode_pointers and discard_mesh_edit_mode_pointers functions of the deg_eval_copy_on_write.cc file.

A copy of the edit_btmesh from mesh_orig is done in the mesh_cow. So the same looptris pointer is used on both meshes.

But when doing an extrusion, the number of looptris changes and the looptris are reallocated in the original mesh causing the mesh_cow pointer to be invalid.

The looptris are reallocated in the BKE_editmesh_tessface_calc function.

Issue is in fact exact same one as with undo/redo: in macros, when next operator needs access to evaluated data, we have to ensure depsgraph is properly evaluated before calling that next operator:

diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index 1d66616a038..4ff98ced9e5 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -640,7 +640,7 @@ static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
 	ot->name   = "Move";
 	ot->description = "Move selected items";
 	ot->idname = OP_TRANSLATION;
-	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA;
 
 	/* api callbacks */
 	ot->invoke = transform_invoke;
diff --git a/source/blender/windowmanager/intern/wm_operator_type.c b/source/blender/windowmanager/intern/wm_operator_type.c
index 89421ac0ab0..9f468825ae6 100644
--- a/source/blender/windowmanager/intern/wm_operator_type.c
+++ b/source/blender/windowmanager/intern/wm_operator_type.c
@@ -43,6 +43,8 @@
 #include "BKE_context.h"
 #include "BKE_idprop.h"
 #include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_scene.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -357,7 +359,7 @@ static int wm_macro_invoke_internal(bContext *C, wmOperator *op, const wmEvent *
 	int retval = OPERATOR_FINISHED;
 
 	/* start from operator received as argument */
-	for (; opm; opm = opm->next) {
+	while (opm) {
 		if (opm->type->invoke)
 			retval = opm->type->invoke(C, opm, event);
 		else if (opm->type->exec)
@@ -374,6 +376,16 @@ static int wm_macro_invoke_internal(bContext *C, wmOperator *op, const wmEvent *
 		else {
 			break; /* operator didn't finish, end macro */
 		}
+
+		opm = opm->next;
+		if (opm != NULL && opm->type->flag & OPTYPE_USE_EVAL_DATA) {
+			/* We need to force refresh of depsgraph after first operator,
+			 * since next one *may* rely on some valid evaluated data. */
+			Main *bmain = CTX_data_main(C);
+			Scene *scene = CTX_data_scene(C);
+			ViewLayer *view_layer = CTX_data_view_layer(C);
+			BKE_scene_view_layer_graph_evaluated_ensure(bmain, scene, view_layer);
+		}
 	}
 
 	return wm_macro_end(op, retval);

@Campbell Barton (campbellbarton) issue with patch above is that it needs to set whole transform operator as 'needing evaluated data', which is not a good idea in redo context (when tweaking a transform value in redo panel e.g.). I think we'll actually need to add a new 'flag_poll' callback to operatortype? That way, we could (optionally) return flags finely tuned to actual needs… E.g. in that case, only set OPTYPE_USE_EVAL_DATA when we actually do snapping on geometry, etc.

I don't really like the idea of keeping a looptris pointer for each object evaluated.
Since the bmesh does not change, these looptris would be exact copies and it would be necessary to make sure to recalculate the looptris in each access.

This is one of the reasons for the reported inefficiency of the transform operator in edit mode.
Since it is not easy to determine when the looptris pointer has been deallocated, the BKE_editmesh_tessface_calc function is always called to do a render_data with looptris in the draw_manager: draw_cache_impl_mesh.c 414.

Therefore the looptris are recalculated at least 3 times at each interaction. One in the operator transform to the original mesh, another in DRW_mesh_batch_cache_get_surface_shaded and one in DRW_mesh_batch_cache_get_overlay_triangles.

Since bmesh does not change, the looptris are the same and should be recalculated only once.

@Germano Cavalcante (mano-wii) that is kind of separated issue, not directly related to that bug imho.