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

Author Topic: Shapes problem  (Read 3305 times)

0 Members and 2 Guests are viewing this topic.

mitrious

  • Newbie
  • *
  • Posts: 11
    • View Profile
Shapes problem
« on: September 20, 2012, 01:20:10 pm »
Consider this simple class and main:

class Foo
{
public:
        Foo() { shape = new sf::CircleShape(100); }
        ~Foo() { delete shape; }
private:
        sf::CircleShape *shape;
};


int main(int argc, char **argv)
{

        Foo f;
        return 0;
}

If I run it it'll crash when trying to free memory allocated for shape when it's being deleted, on the destructor's call. If anyone could try to compile this simple code and see if it crashes it'd be much appreciated.
« Last Edit: September 20, 2012, 03:28:24 pm by mitrious »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Shapes problem
« Reply #1 on: September 20, 2012, 01:42:28 pm »
You're talking about shapes and stuff but in the whole code you provide you never make use of it.
Since you don't have a shape as a member variable I guess you try to delete a local obkect in the destructor which obviously doesn't work. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mitrious

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Shapes problem
« Reply #2 on: September 20, 2012, 01:47:48 pm »
Sorry but you didn't pay much attention to what I wrote, I'm saying that's my base class, if you need something else to go with I will have a, let's say, TestGame class deriving from game which will have a private field, let's call it, shape of the type sf::CircleShape* and we will call new on it on the initialize method (override it from the base class) and then we will delete it on the destructor of the TestGame class

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Shapes problem
« Reply #3 on: September 20, 2012, 02:14:13 pm »
Well then, you still don't provide enough information, showing related code but not the actual problem code won't help us all that much.
At best you should make a minimal and complete example that reproduces the error.
Btw is there really a need for a raw pointer?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mitrious

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Shapes problem
« Reply #4 on: September 20, 2012, 02:21:20 pm »
Actually I explained what I was doing, I just thought anyone could think about a derived class with only one pointer, one call to new and one call to delete. Sorry if I misjudged it, anyways I don't have to use a raw pointer or anything, I just wanna know what's wrong, I don't think something like that should be happening, so posted it here.

mitrious

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Shapes problem
« Reply #5 on: September 20, 2012, 02:28:22 pm »
I will just now edit my post with a full way to reproduce the error and a way to avoid it as well

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Shapes problem
« Reply #6 on: September 20, 2012, 02:49:45 pm »
Well the code is neither minimal nor complete, e.g. what happens in the drawManager?
Have you tried to just take a wibdow and a shape and render it, without all your engune code? Does it also crash?
At which point do hand over the window to the drawManager?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mitrious

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Shapes problem
« Reply #7 on: September 20, 2012, 02:58:35 pm »
Sorry, but you really aren't really reading nor the code nor the comments, plus you're not really helping, the error only occurs in my engine, that's why I'm not posting it as a bug question, but rather as a question only.

if you read the game class there's a method there with a comment saying exactly what it does, that I call in initialize to pass the window object to the drawingManager object in the initialize method, you're just not paying any attention, I commented on the side of each method in the drawing manager saying EXACTLY what it does in order not to make the post even longer.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Shapes problem
« Reply #8 on: September 20, 2012, 03:12:38 pm »
It's nearly impossible to help you, you don't show enough code (3/4 of it are just declarations) but it's already too complicated for us to follow.

You should read this:
http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368
Laurent Gomila - SFML developer

mitrious

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Shapes problem
« Reply #9 on: September 20, 2012, 03:26:27 pm »
I will re-edit the post with one simple class, in which I was able to produce the same crash.


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Shapes problem
« Reply #10 on: September 20, 2012, 03:45:48 pm »
Thanks, things are much clearer now ;)

Your code is correct, so my guess is that you use gcc 4.7 and didn't recompile SFML. Or you mix debug and release.
Laurent Gomila - SFML developer

mitrious

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Shapes problem
« Reply #11 on: September 20, 2012, 03:49:38 pm »
Thank you, but I'm actually using it in Visual Studio and I did not compile it myself actually, I've downloaded it and am using the version that came with it. And as for the debug/release linking, I've just double checked it and it's not it. I will try to compile SFML myself and see if it stops, thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Shapes problem
« Reply #12 on: September 20, 2012, 03:55:32 pm »
Before recompiling SFML, let's find the cause of the problem. What's your version of VC++?
Laurent Gomila - SFML developer

mitrious

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Shapes problem
« Reply #13 on: September 21, 2012, 01:46:13 am »
Well I was using visual studio 2012, I just thought about changing because I hadn't had any problems so far, but it turns out that was it, it works perfectly in VS2010, thx

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Shapes problem
« Reply #14 on: September 21, 2012, 07:05:55 am »
If you had stated in the beginning that you were using VS 2012, we could have help you right then and there, since it's well known that one needs to recompile SFML for VS 2012... ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything