That’s strange. Memory permission error (aka segfault) can be caused by a few things.
- Division by 0
- Accessing an array element out of bounds
- Using an invalid pointer
- Passing a wrong type to a function
- Any other run-time error the compiler does not catch
I might have an idea what is causing your error. If you look at the okapi documentation for
You can see that it accepts values in the range
[-1, 1]. Likewise, if you look at the documentation for the okapi Controller
getAnalog https://pros.cs.purdue.edu/v5/okapi/api/device/controller.html#getanalog you can see it also outputs in the range of
[-1, 1]. The reason okapi chose to use that range is because it represents a percentage instead of an arbitrary number.
However, in your code above, you are not using an okapi Controller, you are using a pros Controller. Looking at that documentation https://pros.cs.purdue.edu/v5/api/cpp/misc.html#get-analog, you can see it outputs values from the range of
[-127, 127], which is not compatible with okapi. The solution might be to switch to using an okapi Controller like this:
I am not convinced that is what is causing the segfault, but give it a try.
If that does not solve the issue, can you show us where you define and create your chassis and controller?