#170632 - Azenris - Thu Oct 08, 2009 7:40 pm
Hi, just wondering if anyone knows why :/
I have the code below which just basically loads a sprite at a point in the level.
below is my new/delete
When I run my program I get a a failure outputting:
the failed new is the first mobile of the level, the player. This is the failing call
Am I out of memory or something? What should I do :/
Ty for any help
_________________
My Homebrew Games
I have the code below which just basically loads a sprite at a point in the level.
Code: |
// =================================================================================
// _LoadSprite: // @ cursor: position to load the sprite // @ spriteID: id of the sprite void CLevelManager::_LoadSprite(u16 cursor, u16 spriteID) { if (spriteID != 0) // ensure it isnt a blank id { CMobile *pMobile = NULL; // pointer to a mobile location loc(cursor, LEVEL_TILES_X, LEVEL_TILES_Y); // change a mappoint into x, y values switch (_GetSpriteType(spriteID)) { // this sprite is not specified, it will be further checked to // see if it is in anyway special or not case SPRITE_TYPE_UNDEF: if (IS_ITEM_CHERRY(spriteID)) ++m_cherriesOnScreen; pMobile = new MEMORY_LEVEL CObject(this, spriteID, 1, loc, false); m_mobiles.push_back(pMobile); break; // the sprite is required to load offscreen case SPRITE_TYPE_OFFSCREEN: pMobile = new MEMORY_LEVEL CObject(this, spriteID, 1, loc, false); pMobile->MakeInvisible(); m_mobiles.push_back(pMobile); break; // the sprite is an enemy case SPRITE_TYPE_ENEMY: pMobile = new MEMORY_LEVEL CEnemy(this, spriteID, 10, loc, false); m_mobiles.push_back(pMobile); ++m_enemiesOnScreen; break; // the sprite is an enemy NYI case SPRITE_TYPE_BOSS: ++m_bossesOnScreen; break; // the sprite is the player case SPRITE_TYPE_PLAYER: m_startingPoint = loc; m_pPlayer = new MEMORY_LEVEL CPlayer(this, spriteID, STARTING_HEALTH, loc); m_mobiles.push_back(m_pPlayer); break; default: DEBUG_HALT("LVL:_LoadSprite - Unidentified Mobile"); break; } if (m_mobiles.size() == MAX_MOBILES) DEBUG_HALT("LVL:_LoadSprite - Mobile Overflow"); } } |
below is my new/delete
Code: |
// =================================================================================
// OPERATOR: new void *operator new(size_t size) { #ifndef _RELEASE_BUILD g_objectCount += 1; g_memorySize += size; size_t memNeeded = size + sizeof(DataHeader); g_memoryHeaderSize += sizeof(DataHeader); char *pMemory = (char*)malloc(memNeeded); if (pMemory == NULL) { PREP_TEST_PRINT printf("\n MEMORY FAILURE\n\n mem header:--%d\n mem data:----%d\n mem total:---%d\n mem objects:-%d\n", GetTotalHeaderMemorySize(), GetTotalMemorySize(), GetTotalHeaderMemorySize() + GetTotalMemorySize(), GetObjectCount()); printf("\n ATTEMPTED ALLOCATION\n\n data size:--------%d\n header size:------%d\n total mem needed:-%d", size, sizeof(DataHeader), size + sizeof(DataHeader)); while(1){} } DataHeader *pHeader = (DataHeader*)pMemory; pHeader->dataSize = size; void *pStart = pMemory + sizeof(DataHeader); return pStart; #else return malloc(size); #endif } // ================================================================================= // OPERATOR: delete void operator delete(void *pData) { #ifndef _RELEASE_BUILD g_objectCount -= 1; DataHeader *pHeader = (DataHeader*)((char*)pData - sizeof(DataHeader)); g_memorySize -= pHeader->dataSize; g_memoryHeaderSize -= sizeof(DataHeader); free(pHeader); #else free(pData); #endif } |
When I run my program I get a a failure outputting:
Code: |
============================= = = MEMORY FAILURE = = mem header:--64 = mem data:----28239 = mem total:---28303 = mem objects:-16 = = ATTEMPTED ALLOCATION = = data size:--------52 = header size:------4 = total mem needed:-56 ============================= |
the failed new is the first mobile of the level, the player. This is the failing call
Code: |
m_pPlayer = new MEMORY_LEVEL CPlayer(this, spriteID, STARTING_HEALTH, loc); |
Am I out of memory or something? What should I do :/
Ty for any help
_________________
My Homebrew Games