[VSCode] Memory Permission Error - 03800320

Hello!

I’m decently new to using the Visual Studio Code extension for VEX-V5, and I’ve been encountering this error that says “Memory Permission Error! 03800320”. I’ve been scavenging through the forums to see if anyone had solutions, but none of them worked. I haven’t used any form of pointers so I doubt I would have a memory leak. Perhaps it’s because of how I structured my project? ( A custom “bg-logic.h” file for background logic, and the main.cpp file only running custom-made functions from the header. ) I’ve only narrowed it down to invoking the drive() function inside “main.cpp”.

main.cpp:

#include <bg-logic.h>

int main() {
    vex::competition compet;

    //> Defines an instance of the custom "vex_robot" class/category.
    c_vex::vex_robot bob(
        4.0, //> Wheel Diameter (inches)
        0.5, //> PID Constant: Proportional
        0.0, //> PID Constant: Integral
        0.0  //> PID Constant: Derivative
    );

    //> Drives the robot forward 24 inches at a speed of 4 inches-per-second.
    bob.drive(24, 4);
}

bg-logic.h:

#include <v5_vcs.h>
#include <math.h>
#include <v5.h>
#pragma once

namespace c_vex {
    class vex_robot {
        private:
            float wheel_diam;

            vex::motor l_motor = vex::motor(2, vex::gearSetting::ratio18_1, false);
            vex::motor r_motor = vex::motor(3, vex::gearSetting::ratio18_1, false);

            float kP;
            float kI;
            float kD;
        ////
        
        public:
            int compet_state = 1; //> 0 = Idle, 1 = Autonomous, 2 = Driver Control

            vex_robot(int wheel_diam, float kP, float kI, float kD) {
                this->wheel_diam = wheel_diam;
                
                this->kP = kP;
                this->kI = kI;
                this->kD = kD;
            }

            bool drive(float distance_in_inches, float inches_per_second = 8) {
                l_motor.stop(vex::brakeType::brake);
                r_motor.stop(vex::brakeType::brake);
                l_motor.resetPosition();
                r_motor.resetPosition();

                int elapsed_time_milli = 0;
                int delta_time_milli   = 20;

                float target_rotation_in_deg = (distance_in_inches / (M_PI * wheel_diam)) * 360.0;
                bool  has_reached_target     = false;

                float l_error_term,  r_error_term;
                float l_prev_error,  r_prev_error;
                float l_derivative,  r_derivative;

                float l_total_error = 0, r_total_error = 0;

                while (compet_state == 1 && !has_reached_target) {
                    l_error_term = target_rotation_in_deg - l_motor.position(vex::rotationUnits::deg);
                    r_error_term = target_rotation_in_deg - r_motor.position(vex::rotationUnits::deg);

                    l_prev_error = l_error_term;
                    r_prev_error = r_error_term;

                    l_derivative = (l_error_term - l_prev_error);
                    r_derivative = (r_error_term - r_prev_error);

                    l_total_error += l_error_term;
                    r_total_error += r_error_term;

                    double l_lat_motor_power_volts = (l_error_term * kP) + (l_total_error * kI) + (l_derivative * kD);
                    double r_lat_motor_power_volts = (r_error_term * kP) + (r_total_error * kI) + (r_derivative * kD);

                    l_motor.spin(vex::directionType::fwd, l_lat_motor_power_volts, vex::voltageUnits::volt);
                    r_motor.spin(vex::directionType::fwd, r_lat_motor_power_volts, vex::voltageUnits::volt);

                    if ((l_error_term >= target_rotation_in_deg && r_error_term >= target_rotation_in_deg)) {
                        has_reached_target = true;
                    }

                    vex::task::sleep(delta_time_milli);
                    elapsed_time_milli += delta_time_milli;
                }

                l_motor.stop(vex::brakeType::brake);
                r_motor.stop(vex::brakeType::brake);
            }
        ////
    };
}

Keep in mind that I’m relatively new to C/C++ in the context of VEX-V5. Thanks!

Actually a weird compiler bug, not seen this one for a while, you declare drive as returning bool, but do not return anything. fix as follows

                l_motor.stop(vex::brakeType::brake);
                r_motor.stop(vex::brakeType::brake);

                return true;
           }
        ////
    };
}
6 Likes

also, unrelated, but just include vex.h, not

#include <v5_vcs.h>
#include <math.h>
#include <v5.h>

v5_vcs was for an old dev environment called vex coding studio, this is visual studio code with the vex extension, completely unrelated, v5_vcs.h will most likely be removed from a future sdk update.

I also edited the topic title to remove VCS

7 Likes

A bit more background

so I called it a bug, that’s because C programmers have been lazy about this for as long as I can remember, but once in a while the “undefined behavior” does cause a problem.

6 Likes

Thanks! I had planned to have it return true if it works and false if it didn’t, but I forgot about that.

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