paavohtl Claude Opus 4.6 (1M context) commited on
Commit
fd089dc
Β·
1 Parent(s): 6dee809

fix: guard display vtable calls for headless mode

Browse files

FUN_570E20 and display vtable[5] call display->vtable[4] which
doesn't exist in headless mode (stripped vtable). Guard both with
if !is_headless.

Headless still crashes in DDGame__InitGameState (0x525B7C) reading
null+0x488 β€” the constructor completes but game state init fails
with our incomplete DDGame state.

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

crates/openwa-core/src/engine/ddgame.rs CHANGED
@@ -647,10 +647,13 @@ unsafe fn init_graphics_and_resources(
647
  }
648
 
649
  // ── FUN_00570E20: usercall(ESI=wrapper), plain RET ──
650
- call_usercall_esi(wrapper, FUN_570E20_ADDR);
 
 
 
651
 
652
  // ── Display vtable slot 5 (offset 0x14) ──
653
- {
654
  let vt = *((*ddgame).display as *const *const u32);
655
  let f: unsafe extern "thiscall" fn(*mut DDDisplay) -> *mut u8 =
656
  core::mem::transmute(*vt.add(5));
@@ -746,7 +749,9 @@ unsafe fn init_graphics_and_resources(
746
  let gfx_handler = (*wrapper)._field_4c0;
747
  let out_buf = wa_malloc(0x900);
748
  core::ptr::write_bytes(out_buf, 0, 0x900);
 
749
  gfx_resource = call_gfx_resource_create(gfx_handler, rb(0x66A3C0) as *const u8, out_buf);
 
750
  }
751
 
752
  // ── PCLandscape (alloc 0xB44, stdcall 11 params) ──
 
647
  }
648
 
649
  // ── FUN_00570E20: usercall(ESI=wrapper), plain RET ──
650
+ // Calls display->vtable[4] which may not exist in headless mode.
651
+ if !is_headless {
652
+ call_usercall_esi(wrapper, FUN_570E20_ADDR);
653
+ }
654
 
655
  // ── Display vtable slot 5 (offset 0x14) ──
656
+ if !is_headless {
657
  let vt = *((*ddgame).display as *const *const u32);
658
  let f: unsafe extern "thiscall" fn(*mut DDDisplay) -> *mut u8 =
659
  core::mem::transmute(*vt.add(5));
 
749
  let gfx_handler = (*wrapper)._field_4c0;
750
  let out_buf = wa_malloc(0x900);
751
  core::ptr::write_bytes(out_buf, 0, 0x900);
752
+ let _ = crate::log::log_line("[DDGame] calling GfxResource_Create");
753
  gfx_resource = call_gfx_resource_create(gfx_handler, rb(0x66A3C0) as *const u8, out_buf);
754
+ let _ = crate::log::log_line(&format!("[DDGame] GfxResource=0x{:08X}", gfx_resource as u32));
755
  }
756
 
757
  // ── PCLandscape (alloc 0xB44, stdcall 11 params) ──