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

Author Topic: SFML Game Development book - bug in the sources?  (Read 2662 times)

0 Members and 1 Guest are viewing this topic.

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
SFML Game Development book - bug in the sources?
« on: March 20, 2016, 12:56:57 am »
So I am reading a book called SFML Game Development (and I really like it), but I think I might have found a major memory leak in the provided sources. If you go to the main repository and check this file:
https://github.com/SFML/SFML-Game-Development-Book/blob/master/10_Network/Include/Book/SceneNode.hpp
you will see that there is no virtual destructor declared. I suppose that's a bug.
Please, fix me if I am wrong.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development book - bug in the sources?
« Reply #1 on: March 20, 2016, 09:25:17 am »
The base classes sf::Transformable and sf::Drawable have a virtual destructors.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: SFML Game Development book - bug in the sources?
« Reply #2 on: March 20, 2016, 10:03:39 am »
OK, got it, thank you. It was dumb of me not to think of that.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML Game Development book - bug in the sources?
« Reply #3 on: March 20, 2016, 10:06:44 am »
Isn't it a good practice to explicitly declare a destructor virtual for an abstract base class, regardless of its own parents? It's clearer for users, and less prone to errors when the code evolves (the parent classes may change, or not be parents anymore). It's like not including a standard header, because you know that some other that you already include does it :P
« Last Edit: March 20, 2016, 11:48:05 am by Laurent »
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development book - bug in the sources?
« Reply #4 on: March 20, 2016, 10:14:19 am »
It arguably is. :P

Declaring ABC destructors virtual can make sense, the same way that e.g. declaring constructors explicit by default or using override can. It's redundant, but helps prevent errors when migrating code.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything