Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call imported static function without instance parameter: not found or instant crash #22

Closed
Roms1383 opened this issue Sep 28, 2023 · 1 comment

Comments

@Roms1383
Copy link
Contributor

I'm currently trying and noticed limitations with corner-case usages of static func:

static without instance on vanilla class

When calling a static func which expects its first parameter to be an instance of itself
e.g. public final static func CanApplyBreathingEffect(player: wref<PlayerPuppet>) -> Bool from example it works ✅

However, static func which does not take any parameter
e.g. public static func GetCriticalHealthThreshold() -> Float (from PlayerPuppet too) causes instant crash with the following error :

// from REDEngine/ReportQueue
Error reason: Unhandled exception
Expression: EXCEPTION_ACCESS_VIOLATION (0xC0000005)
Message: The thread attempted to read inaccessible data at 0x0.
File: <Unknown>(0)

I also tried specifying a fake player: PlayerPuppet as a parameter out of curiosity
e.g. pub fn get_critical_health_threshold(player: PlayerPuppet) -> f32; and then it doesn't crash but instead ends up as expected like:

[2023-09-28 12:20:41.578] [example] [error] Function 'My.TestSystemThruPlayer' has panicked: failed to invoke PlayerPuppet::GetCriticalHealthThreshold;PlayerPuppet: function not found

static without instance on custom class

Another attempt with a custom class of mine like:

module My

public class System extends ScriptableSystem {
    public static func HelloStatic() -> Int32 {
        return 42;
    }
}
#[derive(Default, Clone)]
#[repr(transparent)]
pub struct System(Ref<IScriptable>);

unsafe impl RefRepr for System {
    type Type = Strong;

    const CLASS_NAME: &'static str = "My.System";
}

#[redscript_import]
impl System {
    pub fn hello_static() -> i32;
}

ends up like:

// from mod's RED4ext log
[2023-09-28 11:44:12.381] [example] [error] Function 'My.TestSystem' has panicked: failed to invoke System::HelloStatic;: function not found

Other cases work just fine 👌

It's not blocking for me now since there's workarounds, but I report for completeness.

@Roms1383
Copy link
Contributor Author

This issue is no longer relevant in 0.6.x, it works just fine.

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

No branches or pull requests

1 participant