SFML community forums

Help => Graphics => Topic started by: LedLoaf on November 19, 2020, 11:49:57 pm

Title: Help on an Error after quitting
Post by: LedLoaf on November 19, 2020, 11:49:57 pm
EDIT: So I decided to use the SFML DLLs instead of statically and I no longer get that error. Could anyone explain to me why that is and how I would correct it if I went back to static?

Hello,

After I close my application I get this error. I'm not sure how to track how I would fix this. I would appreciate some help. It bothers me that it appears every time I close the program, the program itself runs fine.


Unhandled exception at 0x00BFABC4 in DungeonGame.exe: 0xC0000005:
Access violation reading location 0x00000000.

(Brings me to GlContext.cpp)

void GlContext::acquireTransientContext()
{
    // Protect from concurrent access
    Lock lock(mutex);

    // If this is the first TransientContextLock on this thread
    // construct the state object
    if (!transientContext)
        transientContext = new TransientContext;

    // Increase the reference count
    transientContext->referenceCount++;  <----------( X ) 'error here'
}
 
Title: Re: Help on an Error after quitting
Post by: eXpl0it3r on November 20, 2020, 10:02:53 am
You probably use some globally initialized SFML resource, which have an undefined destruction order, so the SFML global variables are destructed before your own SFML resource, causing a crash.

Don't use global or static variables, especially for SFML classes.
Title: Re: Help on an Error after quitting
Post by: LedLoaf on November 20, 2020, 07:46:57 pm
Appreciate it, that was the problem. I've had this problem a few times over the years and now that makes complete sense and I did suspect something like that but had no idea why.

Have a good one!