Fix #146398: Crash when exiting sculpt mode in load_post

It is possible, though unlikely, that some sculpt mode runtime data will
be uninitialized when various application handlers run. This commit
makes the minimal change to avoid crashing in this case when exiting
sculpt mode when Dyntopo is enabled.

Pull Request: https://projects.blender.org/blender/blender/pulls/146647
This commit is contained in:
Sean Kim
2025-09-24 09:30:22 +02:00
committed by Sean Kim
parent 1a93cd9148
commit 1c7489b841

View File

@@ -159,8 +159,9 @@ void disable(bContext *C, undo::StepData *undo_step)
void disable_with_undo(Main &bmain, Depsgraph &depsgraph, Scene &scene, Object &ob)
{
SculptSession &ss = *ob.sculpt;
if (ss.bm != nullptr) {
/* This is an unlikely situation to happen in normal usage, though with application handlers
* it is possible that a user is attempting to exit the current object mode. See #146398 */
if (ob.sculpt && ob.sculpt->bm) {
/* May be false in background mode. */
const bool use_undo = G.background ? (ED_undo_stack_get() != nullptr) : true;
if (use_undo) {