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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Adi

Pages: [1]
1
Graphics / [SFML2]sf::Font memory leak
« on: January 10, 2010, 04:09:47 pm »
I found that using function LoadFromFile for sf::Font generates a memory leak (actually a 64 memory leaks for valid loading and 38 when file is not present via Visual Leak Detector 1.9b).

Call Stack:
Code: [Select]
   0x00A3F50A (File and line number not available): glPushAttrib
    0x00A4AD11 (File and line number not available): FT_Done_Memory
    0x00A77E81 (File and line number not available): TT_RunIns
    0x00A30732 (File and line number not available): FT_Load_Char
    0x00A32D94 (File and line number not available): FT_Open_Face
    0x00A33059 (File and line number not available): FT_New_Face
    c:\sfml2\src\sfml\graphics\font.cpp (93): sf::Font::LoadFromFile


Other leaks have info only about
Code: [Select]
0x00A3F50A (File and line number not available): glPushAttrib

So using debugger i discovered that in Cleanup function code responsible for cleaning looks that:
Code: [Select]
if(myRefcount)
{
//cleaning;
}


but myRefcount is set by default constructor to NULL and never set to any value (and in fact before loading from file CLeanup sets it to NULL again and leaves it that way) and cleaning functions are never called.

So a fast fix in LoadFromFile function and LoadFromMemory
Code: [Select]
// Cleanup the previous resources
    Cleanup();
myRefCount = new int;
*myRefCount = 1;

makes memory leaks no more :D

2
Window / [SOLVED] Window Crashing
« on: December 12, 2009, 06:23:05 pm »
Your program crashes because you use Visual Studio 2010, which is still a beta and have errors that makes sfml not working (i don't know why but for example ogre3D also crashes before creating window)

Try downloading Visual C++ Express 2008

3
Window / Detecting if a key was pressed, not if it is always down
« on: December 09, 2009, 10:46:04 pm »
There is also other way to this, without using events. Which is useful when your design makes it impossible or very hard to use events for such tasks.

You can just save previous key state and check if it was released in previous check.

Example:
Code: [Select]
//Should be declared in some warm and safe place (as class member or before main loop :P)
bool previousKeyState;
//Of course name of variable should have some more meaning like prevousShootKeyState etc.

//Actual code
const sf::Input& GetInput = Window.GetInput();

if(GetInput.IsKeyDown(sf::Key::Left) && !previousKeyState)
{
//The Key has been pressed after being released

/*Add some magic code*/

}
else
{
//The Key is not pressed or is being held hostage

/*Some other magic code*/

}

previousKeyState = GetInput.IsKeyDown(sf::Key::Left);
/*I assume this is acceptable because key states are stored as bool[] so compiler will optimize it as an inline and key state can change only after calling GetEvent*/

//End of presentation

Pages: [1]
anything