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

Author Topic: Bugs with constructing and destructing textures in SFML2  (Read 2665 times)

0 Members and 1 Guest are viewing this topic.

Mikademus

  • Newbie
  • *
  • Posts: 31
    • View Profile
Bugs with constructing and destructing textures in SFML2
« on: August 18, 2011, 10:46:00 am »
Hi Laurent,

Using SFML2's Texture class we have discovered the following issues:

First, and least: copying an uninitialised Texture causes an error message to be printed. This could be avoided by changing Texture's copy constructor to
Code: [Select]
{
   if (copy.myTexture)
       LoadFromImage(copy.CopyToImage());
}


Second, when a Texture is destroyed it may use the static Mutex declared in Window/Win32/WglContext.cpp, on line 314. If a static Texture (such as, in our case, an entry in a static/singleton Texture repository class) is destroyed after that Mutex has been destructed, it will cause an access violation. Since it is basically impossible to control the order of destruction for static objects, a destructor should not access any static members, directly or indirectly. We are not familiar enough with SFML's inner structure to feel comfortable suggesting a solution to this problem.

The third issue is not related to Textures, as far as we're aware. We've encountered an access violation in System/Win32/ThreadLocalImpl.cpp, on line 52. The member myIndex had a value characteristic of freed heap memory (0xFEEEFEEE), suggesting that the ThreadLocalImpl object had been destructed. Unfortunately the call stack did not give any useful context in this case, but since it occurred after issue two, above, it is likely a similar problem.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Bugs with constructing and destructing textures in SFML2
« Reply #1 on: August 18, 2011, 10:52:25 am »
Thank you very much for your feedback, I'll fix this as soon as I can :)
Laurent Gomila - SFML developer

Mikademus

  • Newbie
  • *
  • Posts: 31
    • View Profile
Bugs with constructing and destructing textures in SFML2
« Reply #2 on: August 18, 2011, 11:43:56 am »
Quote from: "Laurent"
Thank you very much for your feedback, I'll fix this as soon as I can :)


Thank you for your speedy reply! I hope we were of help and please let us know your findings!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Bugs with constructing and destructing textures in SFML2
« Reply #3 on: August 19, 2011, 06:32:13 pm »
Problem 1 is fixed.

For problem 2 (and possibly 3), I have no solution. The best thing to do is to avoid using globals on your side, especially SFML resources that require an OpenGL context to be constructed or destroyed. Leaving singletons destroy themselves at global exit is a huge source of problems, trust me. You should rather have a way to manually initialize and destroy them, you must keep a total control on it if you want to avoid problems.
Laurent Gomila - SFML developer