Crash on adding printf line in display lambda

Since moving to ESPHOME 2026.4.x I get a crash and rollback if the following line is included, can anyone please help. My YAML has been working for some time, though a recent ESPHome update required that I move a Map out of the Lambda and into YAML. Now this is crashing the display:

it.printf(centre + centre/4, BTop + 80, id(djsans30), TextAlign::TOP_CENTER, "%2.0f%%", (id(battery_soc).state -20)*100/80);

I have other printf lines in the display lambda and they all work fine.

This line does not cause the crash, I added it to see what was happening:
if (isnan(id(battery_soc).state)){

Thank you for any insight into this.

Try
float((id(battery_soc).state - 20.0f) * 100.0f / 80.0f))

Thank you for your suggestion. Unfortunately it did not resolve the issue. It is very odd that this one line is blowing things out since the uplift to 2026.4. I wonder what changed.

I think that it's just getting tighter with correct code.

Try if this works.

float batt = id(battery_soc).state;
if (isnan(batt)) return;
float pct = (batt - 20.0f) * 100.0f / 80.0f;

it.printf(centre + centre/4, BTop + 80,
          id(djsans30),
          TextAlign::TOP_CENTER,
          "%.0f%%",
          pct);

Unfortunately that also crashes it. I can crash and cause rollback with with just this line:
float batt = id(battery_soc).state;

Actually it is some other instability, I have fairly reliably been able to compile and run the code without that line, but since I added your code I have now tried 4 times with bits removed and now back to what I had that was working and every time it is crashing on boot.
It is also taking a very long time to boot, so I think it is actually crashing and re-tryig on the working version of 2026.4 that I have installed and runs fine.

All fixed now that I have updated to 2026.5.0. No more boot crashes and I have re-compiled and uploaded 5 times with various adjustments around that line of code and others, just to see if I could break it.