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

Author Topic: Problem with deleting sf::Font pointer  (Read 4335 times)

0 Members and 1 Guest are viewing this topic.

Nerote

  • Newbie
  • *
  • Posts: 5
    • View Profile
Problem with deleting sf::Font pointer
« on: January 05, 2013, 07:56:40 pm »
Hello, i ran into some trouble when playing around with the sf::Font class.

sf::Font* font = new sf::Font();

delete font;
 

This is not working, just wondering if there's something i've missed?

Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with deleting sf::Font pointer
« Reply #1 on: January 05, 2013, 08:21:22 pm »
You mean that this code doesn't work? (and what does "doesn't work" mean exactly?)

#include <SFML/Graphics.hpp>

int main()
{
    sf::Font* font = new sf::Font();
    delete font;
    return 0;
}

If it works, then please provide a complete code that reproduces the problem.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Problem with deleting sf::Font pointer
« Reply #2 on: January 05, 2013, 08:26:54 pm »
Manual memory management is in C++ kind of depreciated, much nicer is to allocate things on the stack and if it's not possible then use a smart pointer, which will automatically free the resource thanks to RAII.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nerote

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Problem with deleting sf::Font pointer
« Reply #3 on: January 05, 2013, 08:32:19 pm »
I tried to allocate and delete in the main function.
I am using Visual Studio 2012 and it breaks when calling delete in "dbgheap.c"

extern "C" _CRTIMP int __cdecl _CrtIsValidHeapPointer(
        const void * pUserData
        )
{
        if (!pUserData)
            return FALSE;

        if (!_CrtIsValidPointer(pHdr(pUserData), sizeof(_CrtMemBlockHeader), FALSE))
            return FALSE;

        return HeapValidate( _crtheap, 0, pHdr(pUserData) );
}
 

Im having a hard time describing my problem any better.
Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with deleting sf::Font pointer
« Reply #4 on: January 05, 2013, 08:34:38 pm »
Did you recompile SFML? You need to (or get an unofficial nightly build) , since there's no precompiled version for VS2012.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Problem with deleting sf::Font pointer
« Reply #5 on: January 05, 2013, 08:35:43 pm »
Are you using libraries built for your compiler version?
Back to C++ gamedev with SFML in May 2023

Nerote

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Problem with deleting sf::Font pointer
« Reply #6 on: January 05, 2013, 08:36:57 pm »
Yes I have recompiled SFML for this version.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Problem with deleting sf::Font pointer
« Reply #7 on: January 05, 2013, 08:37:47 pm »
Show the actual, complete, minimal int main() which causes the problem.
Is that enough to crash?
int main()
{
sf::Font * font=new sf::Font();
delete font;
}
 
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with deleting sf::Font pointer
« Reply #8 on: January 05, 2013, 08:38:44 pm »
Are you sure that you don't mix debug and release?
Laurent Gomila - SFML developer

Nerote

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Problem with deleting sf::Font pointer
« Reply #9 on: January 05, 2013, 08:46:07 pm »
This code does not work.

#include <SFML\Graphics.hpp>


int main()
{
        sf::Font* font = new sf::Font();
        delete font;

        return 0;
}
 

And im not mixing release and debug.

I just got some response from a friend who said as previous poster stated with putting them on the stack. So i guess i should avoid pointers with the fonts.

Although im a bit confused why i am not able to delete sf::Font's.


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with deleting sf::Font pointer
« Reply #10 on: January 05, 2013, 08:51:33 pm »
The problem is not whether you should do it or not, this code should work. If it doesn't, it means that you have an environment issue that must be fixed, otherwise you won't be able to develop anything with SFML.

How did you recompile SFML, what options did you change in CMake?
Laurent Gomila - SFML developer

Nerote

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Problem with deleting sf::Font pointer
« Reply #11 on: January 05, 2013, 09:04:16 pm »
I followed the tutorial on this website when i recompiled it.
I set the CMAKE_BUILD_TYPE to Debug, rest as the default.
Generator set to Visual Studio 11.

 

anything