I'm trying to make a program that makes the camera follow a certain structure of objects by having a "followbehaviour" class, but I get a access violation at the target object when I try to pass the object to the "followbehaviour" class. I'm fairly new to c++ so any help is helpful.
This is the errorcode:
Exception thrown at 0x7C19FF80 (ucrtbased.dll) in mge.exe: 0xC0000005: Access violation reading location 0x00000000.
The structure passed in here is where the error happens
camera->setBehaviour(new FollowBehaviour(*structure));
main.cpp
GameObject* structure = new GameObject("structure", glm::vec3(0, 0, 0));
structure->add(teapotland);
structure->add(teapot2);
structure->setBehaviour(new KeysBehaviour(25));
_world->add(structure);
camera->setBehaviour(new FollowBehaviour(*structure));
followbehaviour.cpp
#include "mge/behaviours/FollowBehaviour.hpp"
#include "mge/core/GameObject.hpp"
#include "glm.hpp"
FollowBehaviour::FollowBehaviour(GameObject& target):AbstractBehaviour()
{
}
FollowBehaviour::~FollowBehaviour()
{
}
followbehaviour.hpp
#ifndef FollowBehaviour_HPP
#define FollowBehaviour_HPP
#include "mge/behaviours/AbstractBehaviour.hpp"
#include "glm.hpp"
#include "mge/core/GameObject.hpp"
class FollowBehaviour : public AbstractBehaviour
{
public:
FollowBehaviour(GameObject& target);
virtual ~FollowBehaviour();
virtual void update(float pStep);
private:
GameObject _target;
glm::vec3 _offset;
};
#endif // FollowBehaviour_HPP
errorcode [![errorcode][1]][1]
if you need anymore code/information feel free to ask. [1]: https://i.stack.imgur.com/jG4wE.png
this works in my main
Light* light = new Light("light", glm::vec3(0,4,0));
light->scale(glm::vec3(0.1f, 0.1f, 0.1f));
light->setMesh(cubeMeshF);
light->setMaterial(lightMaterial);
light->setBehaviour(new KeysBehaviour(25));
_world->add(light);
User contributions licensed under CC BY-SA 3.0