Memory Permission Error 03081CE4

Hey guys! I just downloaded my program to the brain of my bot and this error popped up the moment I ran the program. The code is down below:

`/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       VEX                                                       */
/*    Created:      Thu Sep 26 2019                                           */
/*    Description:  Competition Template                                      */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

// A global instance of competition
competition Competition;

motor leftmotor = motor(PORT1,gearSetting::ratio18_1,false);
motor rightmotor = motor(PORT20,gearSetting::ratio18_1,true);
motor leftarm = motor(PORT9,gearSetting::ratio36_1,false);
motor rightarm = motor(PORT19,gearSetting::ratio36_1,true);
motor intake = motor(PORT13,gearSetting::ratio36_1,true);

controller H = controller(primary);
controller V = controller(partner);

encoder quad = encoder(Brain.ThreeWirePort.A);

// define your global instances of motors and other devices here

/*---------------------------------------------------------------------------*/
/*                          Pre-Autonomous Functions                         */
/*                                                                           */
/*  You may want to perform some actions before the competition starts.      */
/*  Do them in the following function.  You must return from this function   */
/*  or the autonomous and usercontrol tasks will not be started.  This       */
/*  function is only called once after the V5 has been powered on and        */
/*  not every time that the robot is disabled.                               */
/*---------------------------------------------------------------------------*/

void pre_auton(void) {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // All activities that occur before the competition starts
  // Example: clearing encoders, setting servo positions, ...
}


/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              Autonomous Task                              */
/*                                                                           */
/*  This task is used to control your robot during the autonomous phase of   */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/

void autonomous(void) {
  // ..........................................................................
  // Insert autonomous user code here.
  // ..........................................................................
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              User Control Task                            */
/*                                                                           */
/*  This task is used to control your robot during the user control phase of */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/

void usercontrol(void) {
  // User control code here, inside the loop
  while (1) {
    leftmotor.spin(directionType::fwd,H.Axis3.value(),velocityUnits::pct);
    rightmotor.spin(directionType::fwd,H.Axis2.value(),velocityUnits::pct);
    leftarm.spin(directionType::fwd,V.Axis3.value(),velocityUnits::pct);
    rightarm.spin(directionType::fwd,V.Axis3.value(),velocityUnits::pct);
    intake.spin(directionType::fwd,V.Axis2.value(),velocityUnits::pct);

    if(H.ButtonL1.pressing()==1)
    {
      intake.spin(directionType::fwd,100,velocityUnits::pct);
    }

    else if(H.ButtonL2.pressing()==1)
    {
      intake.spin(directionType::fwd,-100,velocityUnits::pct);
    }

    else
    {
      intake.spin(directionType::fwd,0,velocityUnits::pct);
    }  

            // prevent wasted resources.
  }
}

//
// Main will set up the competition functions and callbacks.
//
int main() {
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  // Run the pre-autonomous function.
  pre_auton();

  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}
`

I’m using VEXcode Pro V5 Text 2.05 right now. Thanks for the help in advance. This is kinda urgent since my team has a competition in like 2 weeks :\

1 Like

See this

Same issue, the encoder is using Brain.ThreeWirePort before it has been created.

6 Likes

Seems like something the super user friendly software could just paper over somehow. Default to some value, if not updated and someone tries to do anything with object either print error or silently delay 10ms.

1 Like

welcome to the real world

This is a common problem with global constructors in C++, the standard only defines that the order in which global constructors are called is guaranteed within one translation unit but not across different translation units. Technically the globals in main.cpp could be created before or after globals in other files.

VEX created the specific mess with Brain.ThreeWirePort by creating the Brain instance automatically and placing in a file named robot-config.cpp, we further made the mess by deciding that a Brain instance should have a triport instance (called ThreeWirePort) as well as an lcd instance (Screen) and an sdcard instance. It sort of makes sense as they are part of the brain, and was an attempt to simplify things, but side effect was then other classes wanting to use a Brain.ThreeWirePort port had to be instantiated after Brain exists.

The specific linker used in VEXcode does in fact order constructors based on file name (alphabetical order), so had we picked “autogen-config.cpp” no one would ever noticed the issue, but we have VCS to blame for that and lack of imagination at that time, no one actually thought about it.

I have thought about ways to fix it, but never come up with anything reasonable.

10 Likes