STATUS_ACCESS_VIOLATION in my bindings

Hi there! I made the bindings for Vigem and now I have some troubles.

My project is https://github.com/DuckerMan/vigem

Sometimes, example xbox crash with this message:

error: process didn't exit successfully: `target\release\examples\xbox.exe` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

Where is the problem with my code?

By the way, in this code sometime s argument is -1553317264 or 556925831 or other. But it's supposed to be 0 - 3

It's the error windows shows when you segfault. This is most probably because of an error in the way you are using pointers in your bindings.

Common causes are dereferencing a null pointer, trying to read from a pointer that points to garbage (e.g. it was produced from uninitialised memory, so the pointer uses whatever was in those bytes before as the address), a function pointer is corrupted (e.g. tried invoking an uninitialised function pointer or a buffer overflow clobbered everything on the stack frame, including the return address).

It could also be that you are passing unexpected data to the native function, and it's blowing up due to a bug/garbage input.

So, I figured out where ACCESS_VIOLATION happens.

pub fn state(&self) -> TargetState {
        dbg!("We're almost there! Getting state...");
        unsafe { TargetState::new((*self.raw).State) }
    }

So, I guess the pointer here is null.

pub fn state(&self) -> TargetState {
        dbg!("
        We're almost there! Getting state...");
        unsafe {dbg!(&(*self.raw)); TargetState::new((*self.raw).State) }
    } 
        We're almost there! Getting state..." = "\n        We\'re almost there! Getting state..."
[src\types\target.rs:36] &(*self.raw) = _VIGEM_TARGET_T {
    Size: error: process didn't exit successfully: `target\release\examples\xbox.exe` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION) 

On this moment crash occurs and I dont know where the problem is

Alright, it happens because of this:

&(*self.raw)

So, what do I have to do?

I can't really give you the answer without having looked at your source code and probably stepping through with a debugger.

You may want to google something like "Troubleshooting Segfault". The language doesn't really matter (Rust, C, C++, etc.) because the techniques are all the same.

This article looked promising... Debugging Segmentation Faults and Pointer Problems - Cprogramming.com

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.