2

When i try and run my program in release mode it goes straigth to

Unhandled exception at 0x6f2426ef (msvcr100.dll) in FPS Game.exe: 0xC0000005: Access violation writing location 0x12817c19.

this is in the static _onexit_t __cdecl _dllonexit_nolock function in onxit.c on line 325 : *((*pend)++) = (_PVFV)func;

and i dont know why i have tried many things i cant get it too work i have sdl linked to my application if thats the reason but i really need help with this.

This is the code which is going wrong its microsofts :

static _onexit_t __cdecl _dllonexit_nolock (
        _onexit_t func,
        _PVFV ** pbegin,
        _PVFV ** pend
        )
{
        _PVFV   *p=NULL;
        size_t oldsize;

        /*
         * First, make sure the table has room for a new entry
         */
        if ( (oldsize = _msize_crt(*pbegin)) <= (size_t)((char *)(*pend) -
            (char *)(*pbegin)) )
        {
            /*
             * not enough room, try to grow the table
             */
            size_t grow=__min(oldsize, MAXINCR * sizeof(_PVFV));
            if((_HEAP_MAXREQ-grow<oldsize) ||
                ((p = (_PVFV *)_realloc_crt((*pbegin), oldsize + grow)) == NULL))
            {
                /*
                 * failed, try to grow by ONEXITTBLINCR
                 */
                grow=MININCR * sizeof(_PVFV);
                if ( (_HEAP_MAXREQ-grow<oldsize) ||
                    ((p = (_PVFV *)_realloc_crt((*pbegin), oldsize + grow)) == NULL ))
                {
                    /*
                     * failed again. don't do anything rash, just fail
                     */
                    return NULL;
                }
            }

            /*
             * update (*pend) and (*pbegin)
             */
            (*pend) = p + ((*pend) - (*pbegin));
            (*pbegin) = p;
        }

        /*
         * Put the new entry into the table and update the end-of-table
         * pointer.
         */
         *((*pend)++) = (_PVFV)func;

        return func;

}
  • Hard to help without seeing a line of code. Do you have global or static variables with complex initialization in your program? – john Sep 04 '12 at 18:12
  • yes i do its an FPS Game and it uses sdl so yes –  Sep 04 '12 at 18:15
  • 1
    No idea what SDL is, but if your program is crashing immediately then the likely cause is a bug in one of the constructors for one of your global variables. Or maybe it's a case of 'the static order initialization fiasco' http://stackoverflow.com/questions/3035422/static-initialization-order-fiasco but as I said just guesses with seeing any code. – john Sep 04 '12 at 18:17
  • sdl is a graphics library for c++ and its got a dll the error is not within my code its in the onexit.c which is a part of the librarys which happends to be in my application i put a break point in my main file int main(int argc,char** argv){ game g; g.start(); return 0; } but it crashes before any of that happens –  Sep 04 '12 at 18:26
  • 1
    Q: Are you using Visual Studio for your C/C++ Compiler? It sounds like the problem might be in some static class (which will be loaded before you hit "main()". Regardless of your compiler/IDE, you *should* be able to get some kind of stack traceback... Q: are either "pend" or "func" anywhere in your code? – paulsm4 Sep 04 '12 at 18:34
  • Yes i am using visual studio and no i have not used pend or func in any of my code –  Sep 04 '12 at 18:37
  • @Mac, just because the crash is in Microsoft's library code does *not* mean that the error is in their code. With almost 100% certainty I would say the error is in your code or your build procedures. – john Sep 05 '12 at 06:18
  • ok i wasnt blaming it all on microsoft but i happens in all my projects that have dlls linked so i think its some sort of error in the compiler or the code my code compiles normaly in mingw –  Sep 05 '12 at 16:26

1 Answers1

1

Based on many years of experience and many similar experiences one of my rules of thumb is "No you haven't just found a bug in the compiler".

Firstly build the release with debug info - this should at least let you see the stack and maybe give you a clue what's going wrong.

Often this sort of problem is caused by

  • using the wrong linker settings, or libraries (this is unique to MSVC / windows)
  • linking against a release library that isn't built with the same code generation options;
  • not initializing variables correctly (which often doesn't show up in debug mode)
  • Not having consistent compilation options across all of the projects
Richard Harrison
  • 19,247
  • 4
  • 40
  • 67
  • thank you il go and have a look and also il try and compile it with code blocks which should work and il also try and have a look at the stack –  Sep 04 '12 at 19:02