From 32c607ffe21f0532b51d40147389eba4a4d44079 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Fri, 13 Oct 2017 11:07:09 -0500
Subject: [PATCH] Ensure fade factor is recalculated if fade height changes

---
 Marlin/src/feature/bedlevel/bedlevel.cpp | 1 +
 Marlin/src/module/planner.h              | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/Marlin/src/feature/bedlevel/bedlevel.cpp b/Marlin/src/feature/bedlevel/bedlevel.cpp
index 7be24d6ecd..aa2d3d97ea 100644
--- a/Marlin/src/feature/bedlevel/bedlevel.cpp
+++ b/Marlin/src/feature/bedlevel/bedlevel.cpp
@@ -139,6 +139,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
 
     planner.z_fade_height = zfh;
     planner.inverse_z_fade_height = RECIPROCAL(zfh);
+    planner.force_fade_recalc();
 
     if (level_active) {
       #if ENABLED(AUTO_BED_LEVELING_UBL)
diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h
index 3d7ec53e00..38ae94d188 100644
--- a/Marlin/src/module/planner.h
+++ b/Marlin/src/module/planner.h
@@ -202,6 +202,10 @@ class Planner {
      */
     static uint32_t cutoff_long;
 
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
+      static float last_raw_lz;
+    #endif
+
     #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
       /**
        * Counters to manage disabling inactive extruders
@@ -273,7 +277,7 @@ class Planner {
        *  Returns 0.0 if Z is past the specified 'Fade Height'.
        */
       inline static float fade_scaling_factor_for_z(const float &lz) {
-        static float z_fade_factor = 1.0, last_raw_lz = -999.0;
+        static float z_fade_factor = 1.0;
         if (z_fade_height) {
           const float raw_lz = RAW_Z_POSITION(lz);
           if (raw_lz >= z_fade_height) return 0.0;
@@ -286,6 +290,8 @@ class Planner {
         return 1.0;
       }
 
+      FORCE_INLINE static void force_fade_recalc() { last_raw_lz = -999.999; }
+
     #else
 
       FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) {