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

Author Topic: sf::String Memory Leak?  (Read 4100 times)

0 Members and 2 Guests are viewing this topic.

MrQuizzles

  • Newbie
  • *
  • Posts: 15
    • View Profile
sf::String Memory Leak?
« on: September 22, 2008, 08:38:16 pm »
This being my first post here, I'd first like to say that I love SFML. I originally started my programming project (a fairly sophisticated shmup engine) in SDL and switched to SFML later. It took me weeks to get to a certain point with things in SDL, and it took me only a day to do it again in SFML. It makes things so much easier. I love it.


Anyways, my program has a memory leak, and I've traced it back to sf::String. It's tiny, very tiny. I'm creating amd destroying 60 of these a second in my test run (I really hope that process is as light as I think it is), and I accrue around 3 kilobytes per second.

I'm using the sf::String object in my own object that inherits from a base class, it contains no pointers whatsoever. It's mirrored by another object inheriting from that same class but uses sf::Sprite in place of sf::String, and that object creates no memory leaks despite being handled with the same code.


The only things I do to sf::String are:
SetSize
SetText
SetFont
SetColor
SetPosition
SetRotation

All done during the constructor of the containing object, then it gets rendered and promptly destroyed.


Can anyone else confirm the occurrence of a memory leak in this object? I can post my code if necessary.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::String Memory Leak?
« Reply #1 on: September 22, 2008, 10:04:04 pm »
AFAIK, there's a memory leak on Windows which caused by some OpenGL drivers. Does it also happen when you draw a sprite or a shape ?
Laurent Gomila - SFML developer

MrQuizzles

  • Newbie
  • *
  • Posts: 15
    • View Profile
sf::String Memory Leak?
« Reply #2 on: September 22, 2008, 10:33:32 pm »
I haven't implemented shape drawing yet, but it does not happen when sprites are drawn.


Edit: I realize I should've said sf::Sprite up there instead of sf::Image. I'm getting all my layering messed up :s

fixus971

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
    • http://www.fixweb.it
sf::String Memory Leak?
« Reply #3 on: September 22, 2008, 11:48:23 pm »
Hi, I have this problem too  :evil:
I discovered it only today after 1 week of research.
Infact I get error only in Release version as general runtime error.
Using traps and testing different codes
I identify problem in sf::String.SetText.
Code: [Select]
OutputDebugStringA( (mRun?"A":"a") );
mDicesString.[b]SetText[/b]("dadi"); // <--- errrrrrrrrrr
OutputDebugStringA( (mRun?"B":"b") );

after SetText mRun bool variable change.
I found that after comment lines where use Draw(mDicesString) to prevent general error in runtime.
I try to move code and variables:
 error change its targhet when move variable definition line.
I worked with 1.3 version and now go to test SVN just downloaded.
^_^=>Il calcolatore è straordinariamente veloce, accurato e stupido. Gli uomini sono incredibilmente lenti, imprecisi e creativi. L'insieme dei due costituisce una forza incalcolabile. (Albert Einstein)

MrQuizzles

  • Newbie
  • *
  • Posts: 15
    • View Profile
sf::String Memory Leak?
« Reply #4 on: September 23, 2008, 04:43:30 pm »
Oh yes, it's definitely in the SetText method. Commenting out that one line in my program got rid of the memory leak.

fixus971

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
    • http://www.fixweb.it
sf::String Memory Leak?
« Reply #5 on: September 23, 2008, 05:09:41 pm »
Hi. Now I using SVN version and problem in String disappear. :D

Unfortunately now have a similar problem when
I go to extract data from a sf:Packet.  :evil:
Always only in Release(:evil:) mode.
I see that data in Packet is correct
but in variables I get very big numbers.
Tonight I'm going to make an apposite experimental project.
^_^=>Il calcolatore è straordinariamente veloce, accurato e stupido. Gli uomini sono incredibilmente lenti, imprecisi e creativi. L'insieme dei due costituisce una forza incalcolabile. (Albert Einstein)

fixus971

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
    • http://www.fixweb.it
sf::String Memory Leak?
« Reply #6 on: September 25, 2008, 08:35:02 am »
Hi, I discovered the source of all problems.  :shock:

In release mode VC9 activate all compiler Optimizations
that boost application removing randomly some code lines.  :evil:

The appearance is that because I setup 1 breakpoints for every line but
in runtime many of that disappear.
but
the problem is that when I active optimization /O1 or /O2
I get very strange results in variables.
If I have:
Code: [Select]
a=1;
b=2;
c=3;

using break points
I see on line b that "a=1" ok!
on line c I see "a=314696412638" grrrr
I don't know how to investigate now..
For now turn off Optimizations.
Byebye
^_^=>Il calcolatore è straordinariamente veloce, accurato e stupido. Gli uomini sono incredibilmente lenti, imprecisi e creativi. L'insieme dei due costituisce una forza incalcolabile. (Albert Einstein)

 

anything