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

Author Topic: use "static sf::Texture texture"as a member of a class  (Read 4169 times)

0 Members and 1 Guest are viewing this topic.

memory4963

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
use "static sf::Texture texture"as a member of a class
« on: May 20, 2016, 10:03:16 pm »
I want to use "static sf::Texture texture"as a member of a class.But when I compiled the code ,there have some wrong with its memory.

my compiler is VS2015.

here is the code:

Game.hpp:

#pragma once

#include"SFML\Graphics.hpp"
#include"SFML\Window.hpp"
#include<iostream>

class Game
{
public:
   Game();
   ~Game();
private:
   static sf::Texture texture;
};

Game.cpp:

#include "Game.hpp"
#include"SFML\Graphics.hpp"
#include"SFML\Window.hpp"

sf::Texture Game::texture;//memory wrong here

Game::Game()
{
}

Game::~Game()
{
}

0x773A5A13 (ntdll.dll)处(位于 Flighter2.exe 中)引发的异常: 0xC0000005: 写入位置(when writting in) 0x00000004 时发生访问冲突(conflict)。

as you see, I'm Chinese, my English is not good.......Thank you very mach for thinkint about my problem,sincerely~~!!

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: use "static sf::Texture texture"as a member of a class
« Reply #1 on: May 21, 2016, 01:08:45 am »
I'm not sure here but since it's a member, it should probably be constructed in the constructor, not separately.

If you want to use a private static variable, why not declare and use it in the cpp, either as static or in an anonymous/unnamed namespace.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Erdrick

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
    • Email
Re: use "static sf::Texture texture"as a member of a class
« Reply #2 on: May 21, 2016, 03:46:26 am »
I found this on the interweb

Cause of Ntdll.dll Errors

The causes of ntdll.dll error messages can vary greatly. However, most ntdll.dll errors result from a corrupt or damaged version of the ntdll.dll file itself, corrupt hardware drivers, or issues between Windows and other programs.

Ntdll.dll errors can sometimes mean that a piece of hardware in your computer is malfunctioning, but this is rare.

How repeatable is this issue and does it repeat itself after a reboot?

memory4963

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: use "static sf::Texture texture"as a member of a class
« Reply #3 on: May 21, 2016, 09:16:28 am »
so there has no way to fix it?  = =

I found this on the interweb

Cause of Ntdll.dll Errors

The causes of ntdll.dll error messages can vary greatly. However, most ntdll.dll errors result from a corrupt or damaged version of the ntdll.dll file itself, corrupt hardware drivers, or issues between Windows and other programs.

Ntdll.dll errors can sometimes mean that a piece of hardware in your computer is malfunctioning, but this is rare.

How repeatable is this issue and does it repeat itself after a reboot?

memory4963

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: use "static sf::Texture texture"as a member of a class
« Reply #4 on: May 21, 2016, 09:20:19 am »
I cant understand the words you said.......
whats the meaning of   "If you want to use a private static variable, why not declare and use it in the cpp, either as static or in an anonymous/unnamed namespace."  ?
Thank you very mach.......

I'm not sure here but since it's a member, it should probably be constructed in the constructor, not separately.

If you want to use a private static variable, why not declare and use it in the cpp, either as static or in an anonymous/unnamed namespace.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: use "static sf::Texture texture"as a member of a class
« Reply #5 on: May 21, 2016, 11:31:42 am »
static member variables are basically global variables and since SFML uses its own globals to manage certain things behind the curtain, there are issues with globally initialized variables.

Personally I'd suggest to not use a static texture and instead use something like a resource holder (see for example the Thor library).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

memory4963

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: use "static sf::Texture texture"as a member of a class
« Reply #6 on: May 21, 2016, 12:02:03 pm »
m not sure whats the problem
reinstalling VS..........  :-[

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: use "static sf::Texture texture"as a member of a class
« Reply #7 on: May 22, 2016, 11:07:43 pm »
do this

const sf::Texture& texture = *Game::texture;