E
E
Evgeny Yakushov2020-05-18 15:44:58
C++ / C#
Evgeny Yakushov, 2020-05-18 15:44:58

Why isn't the CircleShape object available?

When compiling, it says: Exception thrown at 0x0FE581E6 (sfml-graphics-d-2.dll) in infectionGraph.exe: 0xC0000005: Access violation while reading at 0xCDCDCDD5.
And refers to the line: init->circle.setRadius(size);
If you comment it out, then there is an error on the line: window.draw(root->circle);
I understand that the object is not available for some reason

#include <SFML/Graphics.hpp>
#include <stdint.h>

using namespace sf;

#define AMOUNTNODES 10
#define AMOUNTLINKS 5
#define SIZEX 600
#define SIZEY 600

RenderWindow window(VideoMode(SIZEX, SIZEY), "Infection Graph", Style::Close);

struct Node {
  CircleShape circle;
  uint16_t position[2];
  Node * links[AMOUNTLINKS];
  bool healthy = true;
};

class opNode
{
  private:
    uint8_t size;
    const Color & healthy = Color(150, 220, 55, 255);
    const Color & infected = Color(220, 113, 55, 255);
    Node * root = nullptr;
    void initRoot();
    void create(Node * node);
  public:
    opNode(uint8_t size);
    void draw();
};

opNode::opNode(uint8_t size)
{
  this->size = size;
  create(root);
}

void opNode::initRoot()
{
  Node * init = (struct Node*)malloc(sizeof(struct Node));
  //init->circle.setRadius(size);
  init->position[0] = rand() % SIZEX + size / 2 + 1;
  init->position[1] = rand() % SIZEY + size / 2 + 1;
  for (uint16_t i = 0; i < AMOUNTLINKS; i++) init->links[i];
  init->healthy = true;
  root = init;
}

void opNode::create(Node * node)
{
  if (!root) initRoot();
  //for (uint32_t i = 0; i < AMOUNTNODES; i++)
  //{

  //}
}

void opNode::draw()
{
  root->circle.setFillColor(root->healthy ? healthy : infected);
  root->circle.setPosition(root->position[0], root->position[1]);
  window.draw(root->circle);
}

int main()
{
  opNode pluguInc = opNode(20);

  while (window.isOpen())
  {
    Event event;
    while (window.pollEvent(event))
    {
      if (event.type == Event::Closed)
        window.close();
    }

    window.clear(Color(240, 240, 240, 1));

    pluguInc.draw();
    
    window.display();
  }

  return 0;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question