16
General / Visual Studio 2010 Libs
« on: July 18, 2010, 12:08:03 pm »
I could send them to you (SFML 2.0, quite new)
bye,
CBenni::O
bye,
CBenni::O
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.
#include <Windows.h>
#include <SFML/Graphics.hpp>
class style
{
public:
sf::Font Font;
int fs;
sf::Vector2f pos;
style()
: Font(sf::Font::GetDefaultFont()),fs(30),pos(sf::Vector2f(0.f,0.f))
{
}
};
class btn
{
public:
btn(std::string txt)
{
MyValue = sf::Text(txt,st.Font,st.fs);
}
void up()
{
MyValue.SetFont(st.Font);
MyValue.SetCharacterSize(st.fs);
MyValue.SetPosition(st.pos);
}
void add(std::string txt,int at)
{
std::string t=MyValue.GetString();
t.insert(at,txt);
MyValue.SetString(t);
}
void render(sf::RenderTarget* rt)
{
rt->Draw(MyValue);
}
style st;
private:
sf::Text MyValue;
};
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCommand)
{
sf::RenderWindow App(sf::VideoMode(800,600),"Text Bug");
btn b1("Btn1");
b1.st.fs = 35;
b1.st.pos.x = 100;
b1.up();
btn b2("Btn2");
b2.st.fs = 25;
b2.st.pos.x = 400;
b2.up();
btn b3("Btn3");
b3.st.fs = 20;
b3.st.pos.x = 700;
b3.up();
while(App.IsOpened())
{
sf::Event e;
while (App.GetEvent(e))
{
std::string txt = " ";
switch(e.Type)
{
case sf::Event::Closed:
App.Close();
break;
case sf::Event::TextEntered:
txt[0] = (char)e.Text.Unicode;
b2.add(txt,2);
}
}
App.Clear();
b1.render(&App);b2.render(&App);b3.render(&App);
App.Display();
}
return 0;
}
[C++ Fehler] Utf.inl( 28 ): E2478 Für Template 'Utf<8>' wurden zu viele Template-Parameter deklariert
E2478 Too many template parameters were declared for template 'Utf<8>'
#pragma comment(lib, "sfml-systemB.lib")
#pragma comment(lib, "sfml-graphicsB.lib")
#pragma comment(lib, "sfml-mainB.lib")
#include "SFML/Graphics.hpp"
#include "SFML/System.hpp"
Hi,
I keep having problems with using sfml together with this.
So I can make an image manager. So I have the class ImageManager which inherits from ResourceManager.
Then I make a sf::Sprite sp, and suppose I have a boost::shared_ptr<sf::Image> im and I want to assign that image to the sprite. So I go sp.SetImage(*im). But then I get always the white rectangle, because the use count doesn't increase and the resource manager thinks it has the unique pointer to it, so it deletes it.
What can I do?
MyImage.reset(new sf::Image(*MyImage.get()));
Quote from: "CBenni::O"I was playing a bit with the vld (Visual Leak Detector) and SFML, and this piece of Code (taken from the example Code) Throws 83 Memory Leaks!It's highly probable that you applied the leak detector tool in a wrong way. You should get used to it, before you claim SFML.
[...]
Whats the matter?
#include <vld.h>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
int main()
{
// Create the main window
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");
// Load a sprite to display
sf::Image Image;
if (!Image.LoadFromFile("cute_image.jpg"))
return EXIT_FAILURE;
sf::Sprite Sprite(Image);
// Create a graphical string to display
sf::Font Arial;
if (!Arial.LoadFromFile("arial.ttf"))
return EXIT_FAILURE;
sf::Text Text("Hello SFML", Arial, 50);
// Load a music to play
sf::Music Music;
if (!Music.OpenFromFile("nice_music.ogg"))
return EXIT_FAILURE;
// Play the music
Music.Play();
// Start the game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Clear screen
App.Clear();
// Draw the sprite
App.Draw(Sprite);
// Draw the string
App.Draw(Text);
// Update the window
App.Display();
}
return EXIT_SUCCESS;
}
QuoteNo, It's the final version of my framework...
Sorry, I'm lost. Is your problem solved now?
I'm talking about your framework, not the demo (which is the only place where you use std::auto_ptr, right?). An example of memory leak is in FloatingObj: the image used by the sprite is allocated with new but never deleted.
You should really not allocate everything dynamically
By the way, I looked at your code and there are indeed too many pointers and dynamic allocations
None of them are really necessary, and you have many leaks because you don't destroy all the objects that you create with new.