Skip to content

build: no C++ exceptions or RTTI - #7

Merged
finger563 merged 1 commit into
mainfrom
fix/no-exceptions-rtti
Oct 24, 2026
Merged

finger563 merged 1 commit into
mainfrom
fix/no-exceptions-rtti

Conversation

@finger563

Copy link
Copy Markdown
Contributor

Turns off CONFIG_COMPILER_CXX_EXCEPTIONS and CONFIG_COMPILER_CXX_RTTI. Nothing in the firmware needs them: the games and emulator cores are C, nothing uses dynamic_cast or typeid, and the three places that used exceptions didn't need to.

Changes

  • sdkconfig.defaults: both options are off, with a comment explaining why.
  • main/main.cpp: the terminate handler's rethrow-to-print part is compiled only under __cpp_exceptions.
  • components/jk/src/jk.cpp: the frame-buffer reserve() calls check free PSRAM (largest block and total) first, instead of catching std::bad_alloc.
  • OpenJKDF2 → 1e9b699 (esp32p4): stdJSON parses settings with nlohmann's non-throwing parse(..., nullptr, false). Before this, a corrupt or truncated openjkdf2.json terminated the engine; now it reads as empty settings.

Size

The image is 283 KB smaller (9,182,032 → 8,892,304 bytes):

  • .eh_frame: −169 KB
  • code: −66 KB
  • read-only data: −47 KB

With XIP from PSRAM, all of that is PSRAM the code no longer occupies.

Testing (Tab5)

I ran an autostart soak test of about 8 minutes: Phantom Menace → Jedi Knight → MGS → Chrono Trigger → Minish Cap → Sonic 2 → Jedi Knight → Phantom Menace, wrapping round to TPM and JK again. That was 10 launches, about 45 s each.

  • There were no crashes, aborts or resets.
  • JK's engine heap came from the ROM arena each time, with the same frame rates on every launch (about 41 fps in the opening, about 19–20 in-level).
  • JK's frame buffers were reserved every time; the "could not reserve" warning never appeared.
  • Free internal RAM stayed at about 73 KB after every quit, with no leak across launches.
  • Users need to update an existing local sdkconfig themselves (or delete it), because sdkconfig.defaults doesn't override it.

🤖 Generated with Claude Code

Nothing in the firmware needs them: the games and emulator cores are C,
nothing uses dynamic_cast or typeid, and the three exception sites were
optional. The terminate handler's rethrow-to-print is under
__cpp_exceptions; JK's frame-buffer reserve() checks the heap first instead
of catching bad_alloc; OpenJKDF2 1e9b699 parses its settings without
throwing (a corrupt file used to terminate the engine).

The image is 283 KB smaller (.eh_frame's 169 KB, 66 KB of code, 47 KB of
read-only data), all of it PSRAM that code no longer occupies.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

ESP-IDF Size Report for 'Tab5 Emu'

Metric Base PR Delta
FLASH 0 bytes (0.00%) 0 bytes (0.00%) 0 bytes (0.00%)
DRAM 266,678 bytes (60.43%) 267,166 bytes (60.54%) 🔺 +488 bytes (+0.11%)
IRAM 0 bytes 0 bytes 0 bytes
RAM (DRAM+IRAM) 266,678 bytes 267,166 bytes 🔺 +488 bytes (+0.11%)

FLASH uses app .bin size or json2 flash sum. RAM sums DRAM+IRAM via idf_size. Percentages shown when totals are available.
DRAM/IRAM usage does not include memory used by the heap allocator at runtime.
This report was generated by esp-idf-size-delta.

@finger563
finger563 merged commit 3703f57 into main Oct 24, 2026
1 check passed
@finger563
finger563 deleted the fix/no-exceptions-rtti branch October 24, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant