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

Author Topic: Problem using static image and sprite variables  (Read 2301 times)

0 Members and 1 Guest are viewing this topic.

AdventWolf

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Problem using static image and sprite variables
« on: January 11, 2012, 06:26:43 am »
Okay it's been a while since I've been programming but I'm back and I'm suffering from the same error. The thing is, when I use a static image or sprite variable, the program crashes and the "Lock.cpp" file is shown in Visual studio and the debugger points to
Code: [Select]

Lock::Lock(Mutex& mutex) :
myMutex(mutex)
{
    myMutex.Lock();
}


The program does not crash under release mode, ONLY debug. I am linking statically. Here is the code:

Code: [Select]

//example.hpp
#ifndef EXAMPLE_HPP_
#define EXAMPLE_HPP_

#include <SFML\Graphics.hpp>

class Example
{
static sf::Image image;
static sf::Sprite sprite;
};

#endif


Code: [Select]

//example.cpp
#include "example.hpp"

sf::Image Example::image;
sf::Sprite Example::sprite;


Code: [Select]

//main.cpp
#include <iostream>

int main()
{
}



Any advice is appreciated.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem using static image and sprite variables
« Reply #1 on: January 11, 2012, 07:54:56 am »
Don't use global SFML objects, the behaviour is undefined since they use SFML globals internally, and these globals may be constructed after yours.
Laurent Gomila - SFML developer

AdventWolf

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Problem using static image and sprite variables
« Reply #2 on: January 12, 2012, 05:31:51 am »
Ah ok I see, good to know.

 

anything