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

Author Topic: SFML breaks, trying to free the default font  (Read 8966 times)

0 Members and 1 Guest are viewing this topic.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
SFML breaks, trying to free the default font
« on: May 04, 2009, 01:10:38 am »
It happens when I close the window (i.e.: sf::RenderWindow::Close())
There is no OpenGL Context when "dying", and so the default font tries to get it and then everything breaks.

This didn't happen with revision 959.

Info:

SVN Version: r1079 (also happens with SFML 1.4)
Graphics Card: Ati Radeon 9800 pro / Driver: v6.14.0010.6833
OS: Windows XP SP2

File: sfml-svn\trunk\src\SFML\Window\Win32\WindowImplWin32.cpp
Line: 298

Call Stack:

Code: [Select]
atioglx2.dll!016f91f5()
  [Frames below may be incorrect and/or missing, no symbols loaded for atioglx2.dll]
  atioglxx.dll!6932a17a()
  opengl32.dll!_MakeAnyCurrent@16()  + 0x150 bytes
  opengl32.dll!_wglMakeCurrent@8()  + 0x8a bytes
> sfml-window-d.dll!sf::priv::WindowImplWin32::SetActive(bool Active=true)  Line 298 + 0x1c bytes C++
  sfml-window-d.dll!sf::Context::SetActive(bool Active=true)  Line 64 + 0x18 bytes C++
  sfml-graphics-d.dll!sf::priv::GraphicsContext::GraphicsContext()  Line 69 C++
  sfml-graphics-d.dll!sf::Image::DestroyTexture()  Line 776 + 0x8 bytes C++
  sfml-graphics-d.dll!sf::Image::~Image()  Line 117 C++
  sfml-graphics-d.dll!sf::Font::~Font()  + 0x63 bytes C++
  sfml-graphics-d.dll!`sf::Font::GetDefaultFont'::`2'::`dynamic atexit destructor for 'DefaultFont''()  + 0x28 bytes C++
  sfml-graphics-d.dll!_CRT_INIT(void * hDllHandle=0x10000000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 449 C
  sfml-graphics-d.dll!__DllMainCRTStartup(void * hDllHandle=0x10000000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 560 + 0x11 bytes C
  sfml-graphics-d.dll!_DllMainCRTStartup(void * hDllHandle=0x10000000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 510 + 0x11 bytes C
  ntdll.dll!_LdrpCallInitRoutine@16()  + 0x14 bytes
  ntdll.dll!_LdrShutdownProcess@0()  + 0x142 bytes
  kernel32.dll!__ExitProcess@4()  + 0x42 bytes
  kernel32.dll!7c81cab6()
  msvcr90d.dll!___crtExitProcess()  + 0x1b bytes
  msvcr90d.dll!___freeCrtMemory()  + 0x321 bytes
  msvcr90d.dll!_exit()  + 0x12 bytes
  game.exe!__tmainCRTStartup()  Line 599 C
  game.exe!WinMainCRTStartup()  Line 403 C
  kernel32.dll!_BaseProcessStart@4()  + 0x23 bytes



Regards
-Martín

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML breaks, trying to free the default font
« Reply #1 on: May 04, 2009, 08:21:02 am »
Hi

Thanks for the detailed report, but this is the oldest known bug in SFML so I already know this ;)

However I don't think it's related to the context being destroyed when the font tries to use it. Actually, the OpenGL context is never destroyed.
Laurent Gomila - SFML developer

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
SFML breaks, trying to free the default font
« Reply #2 on: May 04, 2009, 11:26:05 pm »
Sorry I posted here. The Graphics forum says "Help", and I thought it was for "How do I...?" questions.

I'll try to get to the root of the problem.
If I find any solution I'll post it here.

Regards
-Martín

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
SFML breaks, trying to free the default font
« Reply #3 on: May 05, 2009, 12:05:22 am »
Found the problem.

Code: [Select]
void WindowImplWin32::ProcessEvent(UINT Message, WPARAM WParam, LPARAM LParam)
{
    //...
    switch (Message)
    {
        // Destroy event
        case WM_DESTROY :
        {
            // Here we must cleanup resources !
            Cleanup();
            break;
        }


Code: [Select]
void WindowImplWin32::Cleanup()
{
    //...

    // Destroy the OpenGL context
    if (myGLContext)
    {
        // Unbind the context before destroying it
        SetActive(false);

        wglDeleteContext(myGLContext);
        myGLContext = NULL;
    }



 :wink:


This is called (callback'd) after win->Close(); or delete win; (Being win a valid RenderWindow)

GraphicContext constructor (GraphicContext.cpp Line 63) re-creates a context out of thin air calling Context::GetGlobal().
Then (I assume) it breaks when trying to free an image from a different context.

You should defer the context deletion after everything else, instead of on the window destroyal.

I would edit and fix the code but I don't have "the big picture" to know where to put it, so I leave it up to you.

It has to be something to do with the order, because if I leave the window opened and never delete it, my app doesn't crash.

Also found a bug (SVN-patch @ http://nitram.cero.googlepages.com/patch_sfml_nitram_2009_05_04.patch)

Regards
-Martín[/code]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML breaks, trying to free the default font
« Reply #4 on: May 05, 2009, 08:34:00 am »
Quote
You should defer the context deletion after everything else, instead of on the window destroyal.

This is just the context owned by the window. There is another one which is, like I said, never destroyed. And they all share their display lists so that a resource created with one can be destroyed with another. So I still don't see the problem here, that's weird.

Quote
Also found a bug (SVN-patch @ http://nitram.cero.googlepages.com/patch_sfml_nitram_2009_05_04.patch)

Hmm? What bug does this solve?
Laurent Gomila - SFML developer

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
SFML breaks, trying to free the default font
« Reply #5 on: May 05, 2009, 07:21:44 pm »
Quote from: "Laurent"
Quote
You should defer the context deletion after everything else, instead of on the window destroyal.

This is just the context owned by the window. There is another one which is, like I said, never destroyed. And they all share their display lists so that a resource created with one can be destroyed with another. So I still don't see the problem here, that's weird.

Quote
Also found a bug (SVN-patch @ http://nitram.cero.googlepages.com/patch_sfml_nitram_2009_05_04.patch)

Hmm? What bug does this solve?


If I skip the Cleanup() (while tracing, "Set next statement"), then it does not break.
So yeah, that's where the problem is coming from. Maybe it's a bad ATI implementation... but anyway it's to be taken in serious consideration.

It's not good that for 30% of Windows players, your game crashes on exit.

The bugfix fixes deleting a NULL pointer. Even if it doesn't crash because the delete operator is NULL-friendly it's not a good coding habit.

Regards
-Martín

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML breaks, trying to free the default font
« Reply #6 on: May 05, 2009, 11:10:35 pm »
Quote
If I skip the Cleanup() (while tracing, "Set next statement"), then it does not break.
So yeah, that's where the problem is coming from

Interesting. That doesn't explain the bug, but it's a good starting point for more debugging. Thanks for your help :)

Quote
The bugfix fixes deleting a NULL pointer. Even if it doesn't crash because the delete operator is NULL-friendly it's not a good coding habit.

I don't think so, I have absolutely no problem deleting a null pointer. At least it saves a condition (ok, it's not really relevant).
Laurent Gomila - SFML developer

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
SFML breaks, trying to free the default font
« Reply #7 on: May 05, 2009, 11:33:58 pm »
Quote

Quote
The bugfix fixes deleting a NULL pointer. Even if it doesn't crash because the delete operator is NULL-friendly it's not a good coding habit.

I don't think so, I have absolutely no problem deleting a null pointer. At least it saves a condition (ok, it's not really relevant).


My mistake, sorry. I just didn't knew that it was part of the standard.

MadMartin

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
SFML breaks, trying to free the default font
« Reply #8 on: May 27, 2009, 01:27:41 pm »
Quote from: "Laurent"
Thanks for the detailed report, but this is the oldest known bug in SFML so I already know this ;)


Any news on this one?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML breaks, trying to free the default font
« Reply #9 on: May 27, 2009, 02:18:42 pm »
It will be working very soon in the SFML 2.0 branch.
Laurent Gomila - SFML developer

MadMartin

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
SFML breaks, trying to free the default font
« Reply #10 on: May 27, 2009, 02:26:58 pm »
Yeah, that's cool.


Don't give up the good work, Laurent  :wink:

drpitch

  • Newbie
  • *
  • Posts: 18
    • View Profile
SFML breaks, trying to free the default font
« Reply #11 on: June 15, 2009, 08:51:44 pm »
Hi all,

It's happening the same to me..It crashes when the application finishes and SFML is freeing all resources (freeing the default font).

This minimal sample application crashes:

Code: [Select]

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main()
{
   sf::String text;
   return 0;
}



Call stack:
Code: [Select]

  atioglxx.dll!69029503()
  [Frames below may be incorrect and/or missing, no symbols loaded for atioglxx.dll]
  opengl32.dll!5f145709()
  opengl32.dll!5f139aad()
  opengl32.dll!5f139c5f()
> sfml-window-d.dll!sf::priv::WindowImplWin32::SetActive(bool Active=true)  Line 302 + 0x1c bytes C++
  sfml-window-d.dll!sf::Context::SetActive(bool Active=true)  Line 64 + 0x18 bytes C++
  sfml-graphics-d.dll!sf::priv::GraphicsContext::GraphicsContext()  Line 69 C++
  sfml-graphics-d.dll!sf::Image::DestroyTexture()  Line 776 + 0x8 bytes C++
  sfml-graphics-d.dll!sf::Image::~Image()  Line 117 C++
  sfml-graphics-d.dll!sf::Font::~Font()  + 0x63 bytes C++
  sfml-graphics-d.dll!`sf::Font::GetDefaultFont'::`2'::`dynamic atexit destructor for 'DefaultFont''()  + 0x28 bytes C++
  sfml-graphics-d.dll!_CRT_INIT(void * hDllHandle=0x007f0000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 446 C
  sfml-graphics-d.dll!__DllMainCRTStartup(void * hDllHandle=0x007f0000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 557 + 0x11 bytes C
  sfml-graphics-d.dll!_DllMainCRTStartup(void * hDllHandle=0x007f0000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 507 + 0x11 bytes C
  ntdll.dll!7c91118a()
  ntdll.dll!7c933ada()
  ntdll.dll!7c920435()
  ntdll.dll!7c92043e()
  ntdll.dll!7c933c88()
  kernel32.dll!7c81cb26()
  msvcr90d.dll!__crtExitProcess(int status=0)  Line 732 C
  msvcr90d.dll!doexit(int code=0, int quick=0, int retcaller=0)  Line 644 + 0x9 bytes C
  msvcr90d.dll!exit(int code=0)  Line 412 + 0xd bytes C
  main.exe!__tmainCRTStartup()  Line 595 C
  main.exe!mainCRTStartup()  Line 399 C
  kernel32.dll!7c817077()
  main.exe!__CTA1?AVexception@std@@()  + 0x86bd bytes C++
  c7fff6b9()


My video card is an ATI Radeon 9550.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML breaks, trying to free the default font
« Reply #12 on: June 15, 2009, 09:00:32 pm »
Quote
It's happening the same to me..

Of course it is, it is fixed only in the SFML 2.0 branch ;)
Laurent Gomila - SFML developer

drpitch

  • Newbie
  • *
  • Posts: 18
    • View Profile
SFML breaks, trying to free the default font
« Reply #13 on: June 15, 2009, 09:18:40 pm »
I'm happy to hear that is fixed on 2.0 branch :D
Meanwhile, I'll remove the Cleanup()  sentence from WindowImplWin32::ProcessEvent method.

Thanks Laurent ;)