Skip to content

Fix crashes and improve input handling#8

Open
spacestate1 wants to merge 1 commit intoyaz0r:masterfrom
spacestate1:pr/crash-fixes
Open

Fix crashes and improve input handling#8
spacestate1 wants to merge 1 commit intoyaz0r:masterfrom
spacestate1:pr/crash-fixes

Conversation

@spacestate1
Copy link
Copy Markdown

Replaces hard crashes (assert/abort) with graceful handling, adds null checks, and maps all Saturn controller buttons.

Files changed

File loading safety

  • AzelLib/PDS.cpp getFileSize() (L524-527): Print error message when file cannot be opened (before assert)
  • AzelLib/PDS.cpp openFileHandle() (L549-554): Return a valid struct with size 0 instead of crashing when fopen fails
  • AzelLib/PDS.cpp loadFile() (L631-634, L673-676): Check for null handle and zero-size files, free resources and return -1 instead of crashing

Dragon model loading

  • AzelLib/dragonData.cpp (L544-551): Skip dragon forms with null filename or missing model file instead of crashing

Menu stubs

  • AzelLib/mainMenuDebugTasks.cpp (L2767-2770): Only advance menu state if submenu task was created; play error sound if not implemented
  • AzelLib/mainMenuDebugTasks.cpp (L2846-2860): Replace assert(0) with Unimplemented() in enemy list, map, system menu, and menu background tasks

Battle system

  • AzelLib/battle/battleDebugList.cpp (L62-87): Implement up/down navigation for battle module selection - cycles through valid entries with wrapping and sound effects (was Unimplemented())
  • AzelLib/battle/battleManager.cpp (L96): Replace assert(0) with break in unhandled switch default case

Inventory

  • AzelLib/menu/inventoryMenu.cpp (L432): Add end iterator for bounds checking
  • AzelLib/menu/inventoryMenu.cpp (L449-451): Break out of loop if item array is full (prevents buffer overflow)
  • AzelLib/menu/inventoryMenu.cpp (L440): Replace assert(0) with Unimplemented() for berserk category

Other

  • AzelLib/town/townCamera.cpp (L94-95): Use default fade color (0x8000) instead of asserting on unknown case
  • AzelLib/PDS_Logger.cpp (L5-11): Add cleanupLoggers() to clear all log buffers on shutdown
  • AzelLib/PDS_Logger.h (L75): Declare cleanupLoggers()
  • PDS/PDS.cpp (L85-87): Call cleanupLoggers() before exit

Input mapping

  • AzelLib/renderer.cpp (L448-453): Map gamepad right shoulder, X, left shoulder, back, guide to Saturn C/X/Z/L/R buttons
  • AzelLib/renderer.cpp (L505-520): Map keyboard A/S/D/Q/W to Saturn C/X/Z/L/R buttons

Merge note

Safe to merge on its own. All changes are defensive - they prevent crashes and add input buttons. Nothing depends on this PR, and it doesn't depend on any other. Good candidate for merging first.

- File loading: add null checks for fopen failures instead of crashing,
  handle missing files gracefully with error return
- Dragon data: skip loading dragon forms when model file is missing
- Menus: replace assert(0) with Unimplemented() in enemy list, map,
  system menu, and menu background tasks; play error sound on
  unimplemented submenu selection
- Battle debug list: implement up/down navigation for battle module
  selection (was Unimplemented)
- Battle manager: remove assert in unhandled switch case
- Inventory: add bounds check on item category array to prevent overflow,
  use Unimplemented() for berserk category
- Town camera: use default fade color instead of asserting on unknown case
- Input: map keyboard A/S/D/Q/W and gamepad shoulders/X/back to Saturn
  C/Z/X/L/R buttons for full controller support
- Logger: add cleanupLoggers() for clean shutdown
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