Hello, I am getting the error in the title when attempting to declare a file which to write output from the robot. So far I seem to have isolated the declaration to the line
FILE* fileWrite = fopen(“/usd/test.txt”, “w”);
Which is identical to the documentation seen here. I do follow this line with further statements which write to the file, however, surrounding those lines with a try-catch still caused the error which is why I believe the line in question is the error.
Is there any special formatting of the SD card that must be implemented or is there perhaps an absolute path that I can write to in order to ensure it is the correct place? Any other possibilities?
Well first of all, fopen and its family are C functions, so they don’t use C++ exceptions anyway. There’s a couple ways I can think of to further debug this:
If you want to stick with C file I/O (i.e. using fopen etc), just add a null check for the file pointer immediately after you try opening it:
FILE* f = fopen("/usd/test.txt", "w");
if (!f) {
// F is null, so handle it
}
You could switch to C++ file I/O, provided you’re using kernel version 3.2.0 or higher, which has different methods for error handling
If you’re using kernel version 3.2.0 or higher, run the program while connected to the PROS terminal. You should see a section that starts with BEGIN STACK TRACE once the segfault occurs, followed by a list of numbers. You can feed these numbers into arm-none-eabi-addr2line to get file names and line numbers corresponding with the instructions on the call stack at the time of the error.
Took a while to get to upgrading the kernel and getting the proper error message, however that is complete now and I am now confused on how to feed the stack trace into arm-none-eabi-addr2line as I’ve never really dealt with that before and the internet is being unhelpful. Thank you for your help so far btw.
I think I got the error message to write correctly, however, it is saying that the error is at the
0x07800c88: opcontrol at E:\PROS\Robotics_New/src/main.cpp:191
Which is the line -
pros::delay(10);
Which is obviously not the error given that it is not at all the code being subject to change. Is there anything I am missing? I am entering the command -
Just confirming that the code hasn’t been modified since you last compiled and/or downloaded it? That would cause either the address or the line number to be incorrect.
Yes I re-uploaded the code to double check. Seems like it is that particular line. Interestingly the line before it does include unverified code and may be the source of the error, but it is certainly pointing to the pros::delay line. For reference the line before is -
fputs(output.c_str(), fileWrite);
with c being a string derived from the motor values and fileWrite being -