Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8317591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:39:22+00:00 2026-06-08T21:39:22+00:00

I have a rather large c++ program including a class Character. In Character.h first

  • 0

I have a rather large c++ program including a class “Character”. In “Character.h” first the struct CharacterSettings is declared, and then the class Character (including their constructors).

Character has (among others) a CharacterSettings* settings and a Point pos.
CharacterSettings has a Point preferredVelocity.

This works fine.

However, when I add any public variable to Character, the program crashes when I call this:

drawLine(character.pos, character.pos+character.settings->preferredVelocity, character.radius/3.0, 128, 80, 0);

The program crashes on this line:

Point operator + (const Point &p2) const
    { return Point(x + p2.x, y + p2.y); }

I assume it’s trying to do character.pos+character.settings->preferredVelocity. The error message I get is

Unhandled exception at 0x004bc4fc in ECMCrowdSimulation.exe: 0xC0000005: Access violation reading location 0x7f80000f.

When I look at it, p2.x and p2.y are undefined. Without the extra variable, they aren’t. I have absolutely no idea what is happening, how to even begin debugging or what information you would need to help me! Any help would be greatly appreciated!

Edit: Well here is at least the Character.h file!

#pragma once

/* 
 * ECM navigation mesh / crowd simulation software
 * (c) Roland Geraerts and Wouter van Toll, Utrecht University.  
 * ---
 * Character: A single moving character in the simulation.
*/

#include "../ECM/GraphComponents/CMNode.h"
#include "VectorOperation.h"
#include "IndicativeRoute.h"
#include "float.h"

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
using std::vector;
#include <queue>
using std::queue;

#define CHARACTER_RELAXATIONTIME 0.5f

typedef vector<CMNode>::iterator node_ptr;
class Corridor;
class CMMResult;

    struct CMEdge;
    class CMMInterface;
    class MicroInterface;
    class CMMSceneTransfer;

    struct CharacterSettings
    {
    private:
        bool index_bb_initialized, index_bb_cp_initialized, index_ir_circle_initialized, index_ir_circle_mu_initialized;
        bool index_2nd_ir_circle_initialized, index_2nd_ir_circle_mu_initialized;

    public:
        // --- Unique identifier within the simulation
        int id;

        // --- Velocity and speed
        Point preferredVelocity;// Newly computed velocity *before* local collision avoidance
        Point newVelocity;      // Newly computed velocity (+ collision avoidance), to be applied in the "next" simulation step

        float total_max_speed;  // Maximum possible speed throughout the entire simulation
        float max_speed;        // Maximum speed at this point in time
        float min_desired_speed;// Minimum speed that the character tries to reach when it is not standing still

        Point lastAttractionPoint;

        // --- IRM parameters
        CMMInterface* cmmImplementation; // the type of indicative route to follow within the corridor, e.g. "shortest path" or "weighted side".
        // Only used in WEIGHTED_SIDE:
        float sidePreference;       // bias to following a certain "side" of the corridor. Must be between -1 (left) and 1 (right).
        float sidePreferenceNoise;  // extra noise factor that will be added to sidePreference at each route element.
        // Used in WEIGHTED_SIDE and SHORTEST_PATH
        float preferred_clearance;  // Distance (m) by which the agent prefers to stay away from obstacles.

        // --- Micro simulation model (e.g. for collision avoidance between characters)
        MicroInterface* microImplementation;// the local model to use
        short micro_maxNrNeighbours;        // the number of neighbours to check in the local model
        float micro_personalSpaceRadius;    // radius of the personal space (m), on top of the character's physical radius.
                                            // Entering this disk (radius + personalSpace) is seen as a 'collision'.

        // --- Corridor/Path pointers
        node_ptr index_bb;          // point on backbone path (used for computing attraction force)
        node_ptr index_bb_cp;       // point on the backbone path(used for computing the closest point)
        curve_ptr index_ir_circle;  // index to last point on the indicative route that intersects with a circle
        float index_ir_circle_mu;   // factor wrt to point on the indicative route that intersects with a circle

        friend Character; // only the Character class can look into private members (WvT: ugly C++ practice, but it does work)

        CharacterSettings(int _id, 
            // speed
            float _total_max_speed, float _min_desired_speed,
            // type of indicative route
            CMMInterface* _cmmImplementation, float _sidePreference, float _sidePreferenceNoise, float _clearance, 
            // type of micro simulation model
            MicroInterface* _microImplementation) :

            id(_id), total_max_speed(_total_max_speed), min_desired_speed(_min_desired_speed), 
            cmmImplementation(_cmmImplementation), sidePreference(_sidePreference), sidePreferenceNoise(_sidePreferenceNoise), preferred_clearance(_clearance),
            microImplementation(_microImplementation)
        {
            // velocities
            newVelocity = Point(0, 0);
            max_speed = total_max_speed;
            preferredVelocity = Point(0, 0);

            // corridor/IRM pointers
            index_bb_initialized = false;
            index_bb_cp_initialized = false;
            index_ir_circle_initialized = false;
            index_ir_circle_mu_initialized = false;

            // default micro settings
            micro_maxNrNeighbours = 5; // default for Karamouzas 2010: 5
            micro_personalSpaceRadius = 0.0f; // default for Karamouzas 2010: 0.5
        }
    };

    class Character
    {
    public:
        Point pos;
        float radius;
        Point prevPos;
        int i;    //The thing that is pretending to be the culprit, without this, it works fine.

        // goal data
        Point goalPos;
        float goalRadius;

        // status flags
        bool reachedGoal;
        bool freeze; // whether or not the character is temporarily frozen
        bool freezeNotified;
        bool reachedDestSet;

        Point velocity; // last used velocity

        // corridor/path pointers
        Point retraction, cp;

        //Contains more detailed settings of agent
        CharacterSettings * settings;

    public:
        // --- constructor
        Character(int _id, Point &_pos, float _radius, 
            // speeds
            float _total_max_speed, float _min_desired_speed,
            // type of indicative route
            CMMInterface* _cmmImplementation, float _sidePreference, float _sidePreferenceNoise, float _clearance,
            // type of micro simulation model
            MicroInterface* _microImplementation) :

            pos(_pos), radius(_radius) 
        {
            settings = new CharacterSettings(_id, _total_max_speed, _min_desired_speed, 
                _cmmImplementation, _sidePreference, _sidePreferenceNoise, _clearance, _microImplementation); 

            velocity = Point(0, 0);
            prevPos=_pos;

            reachedGoal = true;
            freeze = false;
            freezeNotified = false;
            reachedDestSet = false;
            //isProxy = false;
        }

        // --- destructor
        void removeSettings();

        // computing the new actual velocity through an acceleration vector: Euler integration
        inline void integrateEuler(const Point &acc, float dtSim)
        {                   
            settings->newVelocity = velocity + dtSim * acc;
            trim(settings->newVelocity, settings->max_speed);
        }

        inline void updatePos(float dtSim) 
        {       
            prevPos=pos;

            // update velocity
            velocity = settings->newVelocity;

            // update position
            pos += dtSim * velocity;

            // if the character is close to its goal, it should stop moving     
            if(!reachedGoal // goal was not already reached
                && settings->lastAttractionPoint == goalPos 
                && distSqr(pos, goalPos) < 0.25)//goalRadius)
            {   
                reachedGoal = true;
                // (do not reset the velocity, so that we can keep the last walking direction)
            }
        }

        void resetIndices();
        node_ptr &getIndex_bb(Corridor &corridor);
        node_ptr &getIndex_bb_cp(Corridor &corridor);
        curve_ptr &getIndex_ir_circle(IndicativeRoute &ir);
        float &getIndex_ir_circle_mu();
        Point &getRetraction() { return retraction; }
        Point &getClosestPoint() { return cp; }

        // computing the cost of some edge (in A*), by using personal preferences
        float getEdgeCost(const CMEdge& edge, float activeFraction);

        // computing the character's area, based on its radius
        float getArea() const;


    };

The thing that makes everything crash is adding the ‘int i’ .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:39:24+00:00Added an answer on June 8, 2026 at 9:39 pm

    Usually strange problems like this happen when you have incompatibilities between files that were compiled with the older version of the header linked with those compiled with newer versions. In such cases, the layout of the object may be different (in the very least, its sizeof is different) between the two files.

    Therefore, in one file it may look like everything is correct with the object, but once passed to a function in another file, you get completely random behavior.

    In such cases, rebuilding the whole project solves the problem. Better still, try to fix the dependencies if you are manually writing the Makefiles. If you are using gcc/g++, you can use a command like this to generate Makefile acceptable dependencies:

    g++ -MM -MG -Ipath/to/includes/that/should/be/part/of/dependency *.cpp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large old program which has some rather complex graphical displays (all
I have a rather large database that has alot of decimal columns in alot
I have a rather large application that has literally a hundred DDLs with Yes
So I have a rather large openGL program going, and checking for normal memory
I have a rather large program that have some odd behaviour once in a
I have a rather large program that uses Hibernate for its ORM needs. Due
I have rather large project that uses ICU regex classes. Basically it might run
I have a rather large text corpus, of which I would like to check
I have a rather large SQL file which starts with the byte order marker
I have a rather large diff of 2 GIT branches and would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.