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

Author Topic: dbgheap.c; bad pointer passed  (Read 4144 times)

0 Members and 1 Guest are viewing this topic.

HardCoded

  • Newbie
  • *
  • Posts: 23
    • View Profile
dbgheap.c; bad pointer passed
« on: November 02, 2011, 04:05:00 pm »
I recently decided to stop using GLUT because it was just too restrictive =x
I looked around for alternatives and saw SFML recommended, so here I am.

Anyways, I was following the tutorials and reached the Fonts and Texts part when I hit a road block =/

The code I'm using is roughly:
Code: [Select]

sf::Font Font;
Font.LoadFromFile("04B_30_.TTF");
sf::Text Text("Hello, world!", Font);
while (true) {
Window.Draw(Text);
}


It works and all, the text is drawn onto the window but when I close the program, I get this error (from debugging):
Code: [Select]

         /*
         * If this ASSERT fails, a bad pointer has been passed in. It may be
         * totally bogus, or it may have been allocated from another heap.
         * The pointer MUST come from the 'local' heap.
         */
        _ASSERTE(_CrtIsValidHeapPointer(pUserData));

So some bad pointer is being passed or so it is claimed =/

I commented the line: sf::Text Text("Hello, world!", Font);
And the Drawing part and the error never came up.

I'm using SFML 2 (VS2010) and would like to know if I messed up or if it's just a little bug =x

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
dbgheap.c; bad pointer passed
« Reply #1 on: November 02, 2011, 04:13:15 pm »
It may be a known bug:
https://github.com/SFML/SFML/issues/59

But I need to see your exact code to be sure.
Laurent Gomila - SFML developer

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
dbgheap.c; bad pointer passed
« Reply #2 on: November 02, 2011, 04:24:28 pm »
Laurent

This looks like the same bug, as you say, but this bug is really causing us trouble and our new games are nearing completion.

Does it happen if you DON'T use the default font, and what possible fixes are there, aside from complete removal of sf::Text use in our program?

Thanks
SFML 2.1

HardCoded

  • Newbie
  • *
  • Posts: 23
    • View Profile
dbgheap.c; bad pointer passed
« Reply #3 on: November 02, 2011, 04:32:34 pm »
I'm really only doing what I've seen from the tutorials =x
Code: [Select]

//X_RATIO and Y_RATIO are 640 and 480 respectively
int main () {
//Set up the system
sf::RenderWindow App(sf::VideoMode(X_RATIO, Y_RATIO, 32), WINDOW_TITLE);
App.SetFramerateLimit(FPS);

sf::Vector2f center (X_RATIO/2, Y_RATIO/2);
sf::Vector2f half (X_RATIO, Y_RATIO);
sf::View View(center, half);

App.SetView(View);
//Other stuff
sf::Texture Texture;
if (! Texture.LoadFromFile("swapped.jpg")) {
App.Close();
}
sf::Sprite Sprite;
Sprite.SetTexture(Texture);
Sprite.Scale(X_RATIO/Texture.GetWidth(), Y_RATIO/Texture.GetHeight());

//Font/String Stuff
sf::Font Font;
if (! Font.LoadFromFile("04B_30_.TTF")) {
App.Close();
}
sf::Text Text("Hello, world!", Font);
//Main Loop
while (App.IsOpened()) {
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Escape)) {
App.Close();
}

App.Clear(sf::Color(0, 0, 0));

App.Draw(Sprite);
App.Draw(Text);
App.Display();
}

    return 0;
}

Quote

Windows has triggered a breakpoint in ItBotB.exe.

This may be due to a corruption of the heap, which indicates a bug in ItBotB.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while ItBotB.exe has focus.

The output window may have more diagnostic information.


Code: [Select]

> sfml-graphics-d-2.dll!_free_dbg_nolock(void * pUserData, int nBlockUse)  Line 1322 + 0x9 bytes C++
  sfml-graphics-d-2.dll!_free_dbg(void * pUserData, int nBlockUse)  Line 1265 + 0xd bytes C++
  sfml-graphics-d-2.dll!operator delete(void * pUserData)  Line 54 + 0x10 bytes C++
  sfml-graphics-d-2.dll!std::allocator<unsigned int>::deallocate(unsigned int * _Ptr, unsigned int __formal)  Line 182 + 0x9 bytes C++
  sfml-graphics-d-2.dll!std::basic_string<unsigned int,std::char_traits<unsigned int>,std::allocator<unsigned int> >::_Tidy(bool _Built, unsigned int _Newsize)  Line 1998 C++
  sfml-graphics-d-2.dll!std::basic_string<unsigned int,std::char_traits<unsigned int>,std::allocator<unsigned int> >::~basic_string<unsigned int,std::char_traits<unsigned int>,std::allocator<unsigned int> >()  Line 755 C++
  sfml-graphics-d-2.dll!sf::String::~String()  + 0x16 bytes C++
  sfml-graphics-d-2.dll!sf::Text::~Text()  + 0x54 bytes C++
  ItBotB.exe!main()  Line 59 + 0x1c bytes C++
  ItBotB.exe!__tmainCRTStartup()  Line 555 + 0x19 bytes C
  ItBotB.exe!mainCRTStartup()  Line 371 C


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
dbgheap.c; bad pointer passed
« Reply #4 on: November 02, 2011, 05:04:02 pm »
Quote
Does it happen if you DON'T use the default font, and what possible fixes are there, aside from complete removal of sf::Text use in our program?

It doesn't happen if you don't use the default font at all (which can be more tricky than it seems).
But according to the last comment in the issue, there seems to be a workaround to be able to use the default font. But it still looks very strange to me...

Quote
I'm really only doing what I've seen from the tutorials

Yep, so it could rather be a configuration problem. I don't think that you have the same problem as described in the issue.

Did you enable or disable STATIC_STD_LIBS in CMake when compiling SFML?
What CRT (Project options > C/C++ > Code generation > Runtime library) do you use for your own project?
Laurent Gomila - SFML developer

HardCoded

  • Newbie
  • *
  • Posts: 23
    • View Profile
dbgheap.c; bad pointer passed
« Reply #5 on: November 02, 2011, 08:32:10 pm »
I enabled the STATIC_STD_LIBS for CMake and it says "Multi-threaded DLL (/MD)"

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
dbgheap.c; bad pointer passed
« Reply #6 on: November 02, 2011, 09:10:27 pm »
Try to disable STATIC_STD_LIBS. You can't mix different CRTs in the same application.
Laurent Gomila - SFML developer

HardCoded

  • Newbie
  • *
  • Posts: 23
    • View Profile
dbgheap.c; bad pointer passed
« Reply #7 on: November 03, 2011, 12:20:07 am »
Huh..
That fixed it =x
Thanks, although I don't know what these CRTs are for =/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
dbgheap.c; bad pointer passed
« Reply #8 on: November 03, 2011, 07:56:33 am »
It refers to the version of the standard library that you link to.

You problem was that STATIC_STD_LIBS was selecting a static version of the standard library for SFML, and your own project was using a DLL version. So in the end, two separate versions of the standard library were existing in your application. It can be ok if both versions never interact with each other, but it happens all the time. For example, when you create a string in your code you use the operator new of the DLL version of the standard library. But when this string is later destroyed by SFML (in sf::Text), it uses the operator delete of the static version of the standard library. And, finallly, that's where the crash happens ;)
Laurent Gomila - SFML developer

 

anything