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 - Contadotempo

Pages: 1 ... 8 9 [10] 11 12
136
General / Detecting Memory Leaks
« on: December 25, 2010, 02:41:20 pm »
Just tested the storage by inserting a lot of images and then destroyed them. The memory in use was back to the original + a slight overhead so I don't think there's any problem. Thanks Laurent  :wink:

May I ask one more question though? It's unrelated to the problem but this way I won't end up creating another topic.
When I move the Render Window by moving the titlebar with the mouse,

everything that's being drawn on the window stops moving, and after I let the window go everything moves again but becomes out of sync. Is there any way to fix this by not stopping what's being drawn when moving the window? It's probably related to GetFrameTime() function since I use it in every movement but if I remove it, what else could I use to get smooth movements?

Thanks for for all the help, great community!

137
General / Detecting Memory Leaks
« on: December 24, 2010, 06:26:13 pm »
Yeah it appears to be coming from the manager. I tried recompiling SFML (1.6) again just to be sure but it appears they're still there even with the optimized code for the manager. It gives me the exact same leaks. Could be a false positive?

One more thing. I didn't understand very well what's happening in this part specially on the return part:
Quote from: "Laurent"
Code: [Select]
if (bHolder->LoadFromFile(Link))
{
      // same here, you were making 2 searches
      std::pair<ImageMap::iterator, bool> result;
      result = bStore.insert(std::make_pair(Link, bHolder)); //std::make_pair allows shorter syntax

      std::cout << "Gestor de Imagens $ Inserido: " << Link << std::endl;
      return result.first;
}


I made it "return bStore[Link];" (doing 2 searches sadly) again since it couldn't compile with "return result.first;".
error: cannot convert 'std::_Rb_tree_iterator<std::pair<const std::basic_string<char>, sf::Image*> >' to 'sf::Image*' in return

By the way, this made my day haha:
Quote from: "Laurent"
Code: [Select]

bool imStorage::SearchManager(const std::string& Link)
{
    // isn't it cute?
    return bStore.find(Link) != bStore.end();
}

I really need to learn how to use bool types more effectively.
Thanks and sorry for all the trouble  :)

138
General / Detecting Memory Leaks
« on: December 23, 2010, 08:00:59 pm »
Hi,
I wrote an sf::Image manager called "class imStorage" based on an resource manager on the wiki and used Visual Studio 2010's debug mode to detect memory leaks.
For some reason, it's detecting a whole bunch of leaks, however I'm having trouble identifying what could be wrong.

Every image is stored on an std::map:
Code: [Select]
std::map<std::string,sf::Image*> bStore

Here's is the code for getting an image:
Code: [Select]

sf::Image *imStorage::GetImage(std::string Link)
{
    //if the image is already in the map, then return the image from it
    if(SearchManager(Link))
    {
        return bStore[Link];
    }
    //else allocate it from a Link to the path
    else
    {
        sf::Image *bHolder = new sf::Image;

        if(bHolder->LoadFromFile(Link))
        {
            bStore.insert(std::pair<std::string,sf::Image*>(Link,bHolder));
            std::cout << "Gestor de Imagens $ Inserido: " << Link << std::endl;
            return bStore[Link];
        }
        else
        {
        delete bHolder;
        }
return NULL;
    }
return NULL;
}

bool imStorage::SearchManager(std::string Link)
{
    std::map<std::string,sf::Image*>::iterator it;
    it = bStore.find(Link);
    if(it != bStore.end())
    {
        return true;
    }
    else return false;
}





And finally here's the destructor:
Code: [Select]
imStorage::~imStorage()
{
while(bStore.begin()!=bStore.end())
{
delete bStore.begin()->second;
bStore.erase(bStore.begin());
}

}


I get the following messages after executing:
Quote
Detected memory leaks!
Dumping objects ->
{136} normal block at 0x00334C20, 8 bytes long.
 Data: < S      > 14 53 1F 00 00 00 00 00
{135} normal block at 0x00334BD0, 20 bytes long.
 Data: < K3  K3  K3     > D0 4B 33 00 D0 4B 33 00 D0 4B 33 00 CD CD CD CD
{134} normal block at 0x00334B88, 8 bytes long.
 Data: < I3     > D4 49 33 00 00 00 00 00
{133} normal block at 0x003349C8, 384 bytes long.
 Data: <$            K3 > 24 CE 1E 00 01 00 00 00 01 00 00 00 88 4B 33 00
{132} normal block at 0x00334988, 4 bytes long.
 Data: < I3 > C8 49 33 00
Object dump complete.


Problem is, I have no idea what these mean and I can't identify what's causing the leaks.
What could be wrong? Could it be a false positive? Should I use any other memory leak detection tool?

If you have any idea or suggestion please be sure to give me a heads up.
Thanks in advance  :)

139
General / Width of an sf::String
« on: December 22, 2010, 07:21:19 pm »
Oh boy, I should read the documentation with more attention. Forgot about GetRect().
Thanks a bunch  :)

140
General / Width of an sf::String
« on: December 22, 2010, 07:10:46 pm »
Hi, is there any way to get the width of an sf::String like in a sf::Sprite (sf::Sprite::GetSize().x).

I'm trying to create a window with "x" width and "x" would have the width of the sf::String.

Is this possible or I have to configure this manually?
Font size will be always 20.

Thanks in advance
 :)

141
General / Main Menu in SFML need tips
« on: December 06, 2010, 02:09:13 pm »
I don't intend to thread-hijack but I have a question related to main menus as well.
I did the same thing as Friend I think.

First made a background, and then made an image that contained the menu text like this:


I was wondering: What would be the most efficient way to display each option?
Creating a Sprite object for each selection?
Or using just one Sprite object but setting a SetSubRect() each part each frame?
Like this:
Code: [Select]

sMenu.SetImage("The menu image posted loaded into an sf::Image Object");

while(App.IsOpened())
{
        (...)
//Iniciar selected
sMenu.SetSubRect(IntRect(0,25,174, 55));
App.Draw(sMenu);

//Definições unselected
sMenu.SetSubRect(IntRect(0,60,174,90));
App.Draw(sMenu);
}
(...)


142
General / Best way to load the same image multiple times
« on: November 22, 2010, 10:14:09 pm »
Ah I understand.
I don't work with polymorphism very well yet so I'll avoid pointers for now, and keep practising.

Thanks for all the help good sirs  :wink:

143
General / Best way to load the same image multiple times
« on: November 22, 2010, 09:26:09 pm »
That's actually something I've been wondering.
What's the difference between allocating an image with new on "map storage<string, sf::Image*> or allocating it automatically on "map storage<string, sf::Image>"?
Sorry, I know it's a beginner's question  :(

144
General / Best way to load the same image multiple times
« on: November 22, 2010, 04:43:21 pm »
Just one quick question, sorry for bumping the topic again:
If I wanted to destroy the manager completely, would using map::clean() on the destructor be enough? I'm very afraid of memory leaks.

145
General / Best way to load the same image multiple times
« on: November 21, 2010, 09:32:35 am »
Hey, sorry for the late reply.
mooglwy is right, I need to check the wiki more often sorry about that :P . Hope this isn't considered a waste of time.

I'll be trying to make my own manager based on std::map.
This way I'll learn my steps better and earn more experience I guess.
Thanks everyone!

Quote from: "Hiura"

Reusability is the key of success.

Very good point  :)

146
General / Best way to load the same image multiple times
« on: November 17, 2010, 02:45:58 pm »
Quote from: "Hiura"
Yes but it is also destroyed at the end of the function thus you'll get a white sprite (no texture).

Ah let me fix that. I'm planning without testing and these things happen. This is how I have it:
Code: [Select]
//bullet.hpp
using namespace sf;

class wBullet
{
    int speed;
    double x,y;
    Sprite bullet;
    Image bHolder;
    wBullet();
};

Code: [Select]
//bullet.cpp
wBullet::wBullet()
{
    bHolder.LoadFromFile("b.png");
    bullet.SetImage(bHolder);
}

I couldn't find a manager that would suit this situation. Where could I hold the image? Store it in another class and then wBullet would inherit the values from that class?
Not sure if it's a good idea.

147
General / Best way to load the same image multiple times
« on: November 16, 2010, 03:15:34 pm »
Quote from: "Groogy"
Sprite doesn't load images. Sprite render images. To load an image you use sf::Image.

And you don't want to load the same image several times. You load one image one time and have several sprites use that image.

Ah yes, I'm sorry, I rushed the code and didn't even compile it since I was planning the structure on a paper.
The code I had in mind would be:
Code: [Select]
//bullet.cpp
wBullet::wBullet()
{
    Image temp;
    temp.LoadFromFile("b.png");
    bullet.SetImage(temp);
}


But this loads the same image several times right? And there's no need for it. However I'm not sure what to do to prevent this.

Quote from: "Hiura"
Does your bullet need to store the image and the renderer (that is, a sprite) or does it only need to have a renderer ? You could store all your image elsewhere, like in a manager (see manager on the wiki page of the site for some examples).

My point is, you have to structure your classes a little bit more; make some relations between them.

Nope, it doesn't need to store the image, just the renderer. I'm going to check the managers out then.
Any more advices are greatly welcome.

And sorry for my rusty English, it's not my first language  :(

Thanks in advance again

148
General / Best way to load the same image multiple times
« on: November 16, 2010, 11:15:01 am »
Hi,
I'm trying to write a program with a class called wBullet that calls a Sprite with a png image.
This class bullet will create at least 100 objects, and so I was wondering what's the best way to load the same image so many times?

Here's my prototype class:

Code: [Select]
//bullet.hpp

class wBullet
{
    int speed;
    double x,y;
    Sprite bullet;
    wBullet();
};



Code: [Select]
//bullet.cpp
wBullet::wBullet()
{
    bullet.LoadFromFile("b.png");
}



Should I use Sprite::LoadFromFile every time? Will it cause any impact? Or should I try Sprite::LoadFromMemory?

Also, what would be the best way to store all these objects?
An array:
wBullet o1["size of array"]
A vector :
vector<wBullet> o1;
Or anything else?

I understand these are probably newbie questions, but I'm fairly new to C++.

Thanks in advance, keep up the great work!

149
General / [Solved]Draw FPS each second
« on: November 02, 2010, 10:59:44 am »
Aah, that was quite simple after all.
Thank you both   :wink:

150
General / [Solved]Draw FPS each second
« on: October 31, 2010, 06:07:02 pm »
Hi,
I'm trying to make a function that would draw how many FPS were displayed each second.
The original function is:

Code: [Select]
double app_properties::draw_fps()
{
stringstream ss;
getfps=1/(App.GetFrameTime()); //getfps is a float declared in the app_properties class
ss << getfps;
dfps.SetText("FPS: " + (ss.str()).substr(0,2)); //dfps is a font string declared in the app_properties class
App.Draw(dfps);
return getfps;
}


How could I change this and make it draw the FPS only each second?
This is probably very easy to do, but I'm being dumb...

Thanks in advance!

Pages: 1 ... 8 9 [10] 11 12
anything