SFML community forums

Help => General => Topic started by: memory4963 on May 20, 2016, 10:03:16 pm

Title: use "static sf::Texture texture"as a member of a class
Post by: memory4963 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~~!!
Title: Re: use "static sf::Texture texture"as a member of a class
Post by: Hapax 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.
Title: Re: use "static sf::Texture texture"as a member of a class
Post by: Erdrick 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?
Title: Re: use "static sf::Texture texture"as a member of a class
Post by: memory4963 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?
Title: Re: use "static sf::Texture texture"as a member of a class
Post by: memory4963 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.
Title: AW: use "static sf::Texture texture"as a member of a class
Post by: eXpl0it3r 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).
Title: Re: use "static sf::Texture texture"as a member of a class
Post by: memory4963 on May 21, 2016, 12:02:03 pm
m not sure whats the problem
reinstalling VS..........  :-[
Title: Re: use "static sf::Texture texture"as a member of a class
Post by: Estivo on May 22, 2016, 11:07:43 pm
do this

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