none
"Invalid allocation size" error (Visual C++/OGRE/CEGUI).

    Question

  • I am working on a C++ game application. It's being developed in Visual Studio C++ 2005, on a Windows XP SP2 machine, we use OGRE as our graphics engine, and Crazy Eddie GUI (CEGUI) for our user interfaces. When I attempt to run the game, it generates a breakpoint and this is the output:

    ...................................................................................
    First-chance exception at 0x7c812a5b in starClient_d.exe: Microsoft C++ exception: CEGUI::UnknownObjectException at memory location 0x0012d5b4..
    HEAP[starClient_d.exe]: Invalid allocation size - CCCCCD11 (exceeded 7ffdefff)
    starClient_d.exe has triggered a breakpoint

    The breakpoint occurs in the following line of code:

    Code Snippet
    return Ogre::MemoryManager::instance().op_new_vc( reportedSize, gProcessID );

     


    The call stack looks like this:

    =>OgreMain_d.dll!0102d5b2()
    OgreMain_d.dll!0102f5a6()
    >starClient_d.exe!operator new[](unsigned int reportedSize=3435973837) Line 363 + 0x23 bytes (Code A)
    starClient_d.exe!Star::InDataStream::readString() Line 121 + 0x4f bytes (Code B)
    starClient_d.exe!Star::Journal:Big SmileeserializeJournalData(Star::InDataStream & ids={...}) Line 346 + 0x34 bytes (Code C)
    starClient_d.exe!Star::Report::Report(Star::InDataStream & inDataStream={...}) Line 40 (Code D)

    Where:

    Code A
    ---------
    Code Snippet
    inline void *operator new[](size_t reportedSize)
    {
    if( !gProcessID )
    gProcessID = Ogre::MemoryManager::instance()._getProcessID();
    ERROR HERE==> return Ogre::MemoryManager::instance().op_new_vc( reportedSize, gProcessID );
    }

     



    Code B
    ---------

    Code Snippet
    std::string InDataStream::readString()
    {
    int length;

    // read the length first
    length = readInt();

    LINE 121==> char* buffer = new char[length + 1];
    //char buffer[50];

    // Now read the string.
    mIS->read(buffer, length * sizeof(char));

    buffer[length] = 0;

    std::string tmp_string(buffer);

    delete[] buffer;

    return std::string(tmp_string);
    }

     


    Code C
    ---------
    Code Snippet
    void Journal::deserializeJournalData(InDataStream& ids)
    {
    //read the number of entries in this stream
    int numEntries = ids.readInt();

    //read the owner ID of this journal and set class data
    this->ownerID = ids.readInt();

    for(int i = 0; i < numEntries; i++)
    {
    //read the current entryItem-type
    int itemType = ids.readInt();
    Entry* entry;

    //Use the enumerated type to check if the entryItem is a
    //text or picture item
    switch(itemType)
    {
    case TEXT_ITEM:
    //create a new entry and add it to the ToC
    entry = newEntry(new TextItem(" "));

    //Insert the stored values in the stream into the newly created entry
    //in the order they were written
    entry->setTimeStamp(ids.readInt());
    entry->setEntryTitle(ids.readString());
    LINE 346 ==> dynamic_cast(entry->getEntryItemPtr())->setBody(ids.readString());

     


    Code D
    ---------

    Code Snippet
    Report::Report(InDataStream& inDataStream)
    {
    // Variables declaration and initialization.
    std::vector workTableOfContents = (*(this->getTableOfContents()));

    // Clear the vector of pointers to Entry objects.
    workTableOfContents.clear();

    this->deserializeJournalData(inDataStream);
    LINE 40==> }

     


    Any help would be appreciated.
    Sunday, July 22, 2007 5:14 PM

Answers

  • This is not a VC++ thing. However, the error message is quite explicit. You are trying to allocate a very large buffer. There is not even enough address space in a Win32 process to satisfy the request. Also note that the requested size looks suspicious.

     

    Typically code generated in debug mode initializes the function's private part of a stack frame with 0xcc. Consequently, local variables of type int are initialized to 0xcccccccc. I'd take a look at what ids.readInt() returns (the debugger is your friend).

     

    Again remember for something like this

     

    Code Snippet

    void foo() {
    int i; // value of i is undefined as per the C++ standard. Debug mode will initialize it to 0xcccccccc to provide hints for debugging

    // ...

    }

     

    Also you can break on first-chance exceptions. When an exception is thrown the debugger get a notification (first-chance). The default mode is to continue execution to give your application a chance to catch the exception. If no handler (no matching catch for C++ exceptions, no __except filter, which opts to swallow the exception) is found the OS notifies the debugger again (second-chance). This would normally be where DrWatson kicks in without a debugger. Most debuggers will just break execution and notify you of the problem.

     

    -hg

    Sunday, July 22, 2007 7:11 PM

All replies

  • This is not a VC++ thing. However, the error message is quite explicit. You are trying to allocate a very large buffer. There is not even enough address space in a Win32 process to satisfy the request. Also note that the requested size looks suspicious.

     

    Typically code generated in debug mode initializes the function's private part of a stack frame with 0xcc. Consequently, local variables of type int are initialized to 0xcccccccc. I'd take a look at what ids.readInt() returns (the debugger is your friend).

     

    Again remember for something like this

     

    Code Snippet

    void foo() {
    int i; // value of i is undefined as per the C++ standard. Debug mode will initialize it to 0xcccccccc to provide hints for debugging

    // ...

    }

     

    Also you can break on first-chance exceptions. When an exception is thrown the debugger get a notification (first-chance). The default mode is to continue execution to give your application a chance to catch the exception. If no handler (no matching catch for C++ exceptions, no __except filter, which opts to swallow the exception) is found the OS notifies the debugger again (second-chance). This would normally be where DrWatson kicks in without a debugger. Most debuggers will just break execution and notify you of the problem.

     

    -hg

    Sunday, July 22, 2007 7:11 PM
  • I assume the line:

    char* buffer = new char[length + 1];

    is the line in readString where the error is occuring. So check to see what value length has; it is probably very large. So add code to check to ensure that the readInt is successful. You need a way for callers of readInt to know there is a problem when there is. Probably the file is bad. Do you have code that ensures the open is successful? If not, then that is an example of ignoring errors and then the program encounters a more serious error that can't be ignored and is more difficult to diagnose.

    Sunday, July 22, 2007 7:13 PM