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

Author Topic: Simply problem with sprites, image and draw  (Read 3262 times)

0 Members and 2 Guests are viewing this topic.

Nesvi

  • Newbie
  • *
  • Posts: 12
    • View Profile
Simply problem with sprites, image and draw
« on: August 07, 2012, 11:04:23 pm »
Hello,
Since 2 weeks i have been trying to debbug a simply class that i made. Is a class that i will use to manage the objects of my game. I have reduced it to the minimal components, it has sprite, image and it uses heritage to get a pointer to the RenderWindow. I have tracked the bug, and the segfault is in the second App->Draw section, into the Draw() method of entity. Im using sfml 1.6

Here is the header:


#ifndef _entity
#define _entity

class Entity : public SharedData{

 private:

  sf::Sprite Mine;
  sf::Image imag;
  int x,y;
 
 public:

  Entity(const int&, const int&, const int&);
  void Draw();
  void SetType(const int&);
  void SetPosition(const int&,const int&);

};

#endif


 

Here is the source:


Entity::Entity(const int& xx,const int& yy, const int& a){

  if(!imag.LoadFromFile("Entitys.tga")) std::cout << "Error " << std::endl;
 
  imag.SetSmooth(false);

  Mine.SetImage(imag);
  Mine.SetPosition(0,0);
  Mine.SetCenter(0,0);
  App->Draw(Mine);
  App->Display();

}

void Entity::SetPosition(const int& xx ,const int& yy){
 
 
}

void Entity::SetType(const int& a){
 
}

void Entity::Draw(){

  Mine.SetImage(imag);
  App->Draw(Mine);
  std::cout << "Im alive" << std::endl;
}


 

The gdb said me this:


Program received signal SIGSEGV, Segmentation fault.
0x0804d024 in std::_Rb_tree<sf::ResourcePtr<sf::Image>*, sf::ResourcePtr<sf::Image>*, std::_Identity<sf::ResourcePtr<sf::Image>*>, std::less<sf::ResourcePtr<sf::Image>*>, std::allocator<sf::ResourcePtr<sf::Image>*> >::_M_begin (this=0x1)    at /usr/include/c++/4.4/bits/stl_tree.h:482
482           { return static_cast<_Link_type>(this->_M_impl._M_header._M_parent); }

 

Thanks :P
« Last Edit: August 08, 2012, 12:15:10 am by Nesvi »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Simply problem with sprites, image and draw
« Reply #1 on: August 08, 2012, 02:05:17 am »
The whole class doesn't really help if you don't provide the code that stand in context with (window creation, event handling, etc.), minimal and complete means that anyone can go grab the code and fully compile and execute the application (until it crashes).

I strongly advice you to use SFML 2. ;)

Also where does the variable 'App' come from? If you inherit it from the SharedData class, than you'll have to initialize that variable (except if it's static), but like I said we can only guess things.
Also your whole class design is very bad. You should always seperate logic from drawing and calling draw in a constructor is never a good idea for an entity class.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nesvi

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Simply problem with sprites, image and draw
« Reply #2 on: August 08, 2012, 03:27:58 am »
Hello,

I will try to use SFML 2.0

I think that you dont need the whole code because it has 6000 lines of code and the error appears into the RenderWindow::Draw() method. I have used the library and i thinked that i could put a simply sprite into a class but it doesnt work! I have checked all, the App (RenderWindow*) is fine all the time then when i call Entity::Draw() it must draw the sprite. But segfault... i was trying to solve this since 2 weeks and now i think that it only can be the RenderWindow::Draw(Sprite) method.
The class SharedData is a class that contains a static pointer to my renderwindow app(and other things that arent overlayed with my variables). Sorry about the design of my class, but is only a test, i put the App->Draw() in the constructor to check if it could work. It works in the constructor but it doesnt works in the Draw() method. About the separation of the logic and the graphics, currently in the class there i was only trying to make the graphics part but i was thinking in creating methods into the same entity class but separated in the two purposes(some methods for logic and others for graphics). Is this correct?

Thanks for the answer and help :)
« Last Edit: August 08, 2012, 03:35:03 am by Nesvi »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Simply problem with sprites, image and draw
« Reply #3 on: August 08, 2012, 09:40:21 am »
I think that you dont need the whole code because it has 6000 lines of code and the error appears into the RenderWindow::Draw() method.
You've read the part about minimal and complete example, right?
 You see I can't find a problem in the provided class so I guess you're doing somewhere, something very wrong. So if you think we don't need to see more, then I'll think you can fix the problem on your own. ;)
Remember it's you that wants help. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nesvi

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Simply problem with sprites, image and draw
« Reply #4 on: August 08, 2012, 09:09:24 pm »
Sorry, i didnt understand you correctly (english is a bit hard for me), im transforming all the project to SFML 2.0 and then i will see if it works. I like the 2.0 version, it is more optimized but i must make some changes. I will report the result. Thanks ;)

Nesvi

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Simply problem with sprites, image and draw
« Reply #5 on: August 13, 2012, 02:10:12 pm »
I have upgrade my project to SFML 2.0 and now all works fine ;)
Thanks eXpl0it3r