jac3km4 / red4ext-rs

Automagical Rust binding to RED4ext
MIT License
18 stars 5 forks source link

Reading Opt from StackFrame arg always return its Default #58

Open Roms1383 opened 3 months ago

Roms1383 commented 3 months ago

I discovered a minor bug in the feature I added, in this specific context:

unsafe extern "C" fn detour(
    i: *mut IScriptable,
    f: *mut StackFrame,
    a3: VoidPtr,
    a4: VoidPtr,
    cb: unsafe extern "C" fn(i: *mut IScriptable, f: *mut StackFrame, a3: VoidPtr, a4: VoidPtr),
) {
    let frame = &mut *f;
    let state = frame.args_state();

    let event_name: CName = StackFrame::get_arg(frame);
    let entity_id: Opt<EntityId> = StackFrame::get_arg(frame); // ❌ will always be Opt::Default, no matter the value
    let emitter_name: Opt<CName> = StackFrame::get_arg(frame); // ❌ will always be Opt::Default, no matter the value

I'm not sure how to fix it or even if it's "fixable". I'm leaving it here as a reminder.

Roms1383 commented 3 months ago

An easy fix for this:

// ...

let event_name: CName = StackFrame::get_arg(frame);
let entity_id: EntityId = StackFrame::get_arg(frame);
let emitter_name: CName = StackFrame::get_arg(frame);

let entity_id: Opt<EntityId> = entity_id.into();
let emitter_name: Opt<CName> = emitter_name.into();