Fix T74205. Intended to to fix the assertion error caused by having step_init != NULL by modifying the undo depth to match what sculpt mode undo expects. Typically, this value (wm->op_undo_depth) is 1 while doing a cancel (canceling operation with right click/escape), however sculpt mode (which handles its own undos) needs this value to be zero. The reason it is not zero is because of line 1988 of blender/source/blender/windowmanager/intern/wm_event_system.c (wm_handler_operator_call) which is:
if (ot->flag & OPTYPE_UNDO) {
wm->op_undo_depth++;
}Alternative solution, which also "works" but has a worse user experience (have to hit ctrl+z multiple times, and probably other problems as well):
Essentially sculpt mode does all its ops differently (which is fine because it handles it own stuff) but for rotates etc. it borrows the other ones, which all set OPTYPE_UNDO, which it explicitly doesn't:
/* Flags (sculpt does own undo? (ton)). */ ot->flag = OPTYPE_BLOCKING;
line 8355 blender/source/blender/editors/sculpt_paint/sculpt.c SCULPT_OT_brush_stroke
Adding OPTYPE_UNDO and removing condition from sculpt_undo_push_end(void) is another solution, but then you have to hit Ctrl+Z a few times before it actually undoes anything :/