Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: _Pnode read access violation error in Text.setFont()  (Read 3464 times)

0 Members and 1 Guest are viewing this topic.

JQ

  • Newbie
  • *
  • Posts: 6
    • View Profile
_Pnode read access violation error in Text.setFont()
« on: August 15, 2018, 01:04:31 pm »
Hello! I've got every time error when I trying in my class  set font to Text.
Full error:" Exception thrown: read access violation.
**_Pnode** was 0xFFFFFFFFFFFFFFE6."
Full script with main()
Quote
#include "stdafx.h"
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include "JQEText.h"


using namespace sf;
using namespace std;

ContextSettings settings;

Font font;
Text test;
map<int,string> numbers;
//numbers["count"] = 6;
   int main()
   {
#pragma region Start



      settings.antialiasingLevel = 8;
      RenderWindow engine{ VideoMode{ 1920,1000 }, "JQEngine",0,settings };
      engine.setFramerateLimit(60);
      Event event;
      engine.setPosition(Vector2i(0,0));
      font.loadFromFile("Arkitech.ttf");
      JQEText text = JQEText(25, font, "test", Vector2f(0, 0), Color(255, 255, 255));
      
      

      
      //mousePosition.setColor(Color(0, 0, 0, 255));

      
#pragma endregion
      
      
      while (true)
      {
         
         
         engine.clear(Color(255 * 0.4, 255 * 0.4, 255*0.4, 255));
         engine.pollEvent(event);
         if (event.type == Event::Closed)
         {
            engine.close();
            break;
         }
         else if (event.type == Event::MouseButtonPressed)
         {

            //Mouse::getPosition(engine).x Mouse::getPosition(engine).y;
            
         }
         
         
         
         engine.draw(test);
         engine.draw(text);
         engine.display();
         
      }
      return 0;
   }
Full class.h
Quote
#pragma once
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <cstdlib>
#include <ctime>
#include <string>
#include <Windows.h>

using namespace sf;
using namespace std;

class JQEText : public Drawable
{
public:
   JQEText(int size, Font font, string ttext, Vector2f position, Color color);
   ~JQEText();
   Text text;
private:

   void draw(RenderTarget& target, RenderStates state) const override;
};
Full class.cpp
Quote
#include "stdafx.h"
#include "JQText.h"


JQText::JQText(int size, Font font, string ttext, Vector2f position, Color color)
{
   text.setCharacterSize(size);
   text.setFont(font); // when I added "//" before that command I don't get this error
   text.setString(ttext);
   text.setPosition(position);
   text.setFillColor(color);
}


JQText::~JQText()
{
}
void JQText::draw(RenderTarget& target, RenderStates state) const
{
   target.draw(text, state);
}

« Last Edit: August 15, 2018, 01:12:22 pm by JQ »

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: _Pnode read access violation error in Text.setFont()
« Reply #1 on: August 15, 2018, 02:21:52 pm »
Don't use globals. SFML doesn't support having it's resources (ContextSettings, Font and Text in your case) as globals. It's also a bad design.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

JQ

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: _Pnode read access violation error in Text.setFont()
« Reply #2 on: August 15, 2018, 03:08:03 pm »
Don't use globals. SFML doesn't support having it's resources (ContextSettings, Font and Text in your case) as globals. It's also a bad design.
How Can I make this resources don't global? I tried something like that:
Quote
#include "stdafx.h"
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include "JQEText.h"


using namespace sf;
using namespace std;



map<int,string> numbers;
//numbers["count"] = 6;
   int main()
   {
#pragma region Start

      ContextSettings settings;

      Font font;

      settings.antialiasingLevel = 8;
      RenderWindow engine{ VideoMode{ 1920,1000 }, "JQEngine",0,settings };
      engine.setFramerateLimit(60);
      Event event;
      engine.setPosition(Vector2i(0,0));
      font.loadFromFile("Arkitech.ttf");
      JQEText text = JQEText(25, font, "test", Vector2f(0, 0), Color(255, 255, 255));
      
      

      
      //mousePosition.setColor(Color(0, 0, 0, 255));

      
#pragma endregion
      
      
      //rest of code
   }
And I still got this error

 

anything