BOOLEAN Copy8BPPImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect ) { UINT32 uiSrcStart, uiDestStart, uiNumLines, uiLineSize; UINT32 rows, cols; UINT8 *pSrc, *pSrcTemp; UINT16 *pDest, *pDestTemp; UINT16 *p16BPPPalette; p16BPPPalette = hImage->pui16BPPPalette; // Assertions Assert( p16BPPPalette != NULL ); Assert( hImage != NULL ); // Validations CHECKF( hImage->p16BPPData != NULL ); CHECKF( usX >= 0 ); CHECKF( usX < usDestWidth ); CHECKF( usY >= 0 ); CHECKF( usY < usDestHeight ); CHECKF( srcRect->iRight > srcRect->iLeft ); CHECKF( srcRect->iBottom > srcRect->iTop ); // Determine memcopy coordinates uiSrcStart = srcRect->iTop * hImage->usWidth + srcRect->iLeft; uiDestStart = usY * usDestWidth + usX; uiNumLines = ( srcRect->iBottom - srcRect->iTop ); uiLineSize = ( srcRect->iRight - srcRect->iLeft ); CHECKF( usDestWidth >= uiLineSize ); CHECKF( usDestHeight >= uiNumLines ); // Convert to Pixel specification pDest = ( UINT16*)pDestBuf + uiDestStart; pSrc = hImage->p8BPPData + uiSrcStart; DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, String( "Start Copying at %p", pDest ) ); // For every entry, look up into 16BPP palette for( rows = 0; rows < uiNumLines-1; rows++ ) { pDestTemp = pDest; pSrcTemp = pSrc; for ( cols = 0; cols < uiLineSize; cols++ ) { *pDestTemp = p16BPPPalette[ *pSrcTemp ]; pDestTemp++; pSrcTemp++; } pDest += usDestWidth; pSrc += hImage->usWidth; } // Do last line DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, String( "End Copying at %p", pDest ) ); return( TRUE ); }
void MemFreeReal( PTR ptr, const STR8 pcFile, INT32 iLine ) { UINT32 uiSize; if ( !fMemManagerInit ) DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFree: Warning -- Memory manager not initialized -- Line %d in %s", iLine, pcFile) ); if (ptr != NULL) { uiSize = _msize(ptr); guiMemTotal -= uiSize; guiMemFreed += uiSize; _free_dbg( ptr, _NORMAL_BLOCK ); #ifdef DEBUG_MEM_LEAKS DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemFree %p: %d bytes (line %d file %s)", ptr, uiSize, iLine, pcFile) ); #endif } else { DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFree ERROR: NULL ptr received (line %d file %s)", iLine, pcFile) ); } // count even a NULL ptr as a MemFree, not because it's really a memory leak, but because it is still an error of some // sort (nobody should ever be freeing NULL pointers), and this will help in tracking it down if the above DbgMessage // is not noticed. MemDebugCounter--; }
PTR MemAllocLocked( UINT32 uiSize ) { PTR ptr; if ( !fMemManagerInit ) DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAllocLocked: Warning -- Memory manager not initialized!!! ") ); ptr = VirtualAlloc( NULL, uiSize, MEM_COMMIT, PAGE_READWRITE ); if ( ptr ) { VirtualLock( ptr, uiSize ); guiMemTotal += uiSize; guiMemAlloced += uiSize; MemDebugCounter++; } else { DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAllocLocked failed: %d bytes", uiSize) ); } #ifdef DEBUG_MEM_LEAKS DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemAllocLocked %p: %d bytes", ptr, uiSize) ); #endif return( ptr ); }
PTR MemAllocReal( UINT32 uiSize, const STR8 pcFile, INT32 iLine ) { PTR ptr; if( !uiSize ) { return NULL; } if ( !fMemManagerInit ) DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAlloc: Warning -- Memory manager not initialized -- Line %d in %s", iLine, pcFile) ); ptr = _malloc_dbg( uiSize, _NORMAL_BLOCK, pcFile, iLine ); if (ptr != NULL) { guiMemTotal += uiSize; guiMemAlloced += uiSize; MemDebugCounter++; } else { DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAlloc failed: %d bytes (line %d file %s)", uiSize, iLine, pcFile) ); } #ifdef DEBUG_MEM_LEAKS DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemAlloc %p: %d bytes (line %d file %s)", ptr, uiSize, iLine, pcFile) ); #endif return( ptr ); }
void MemFreeLocked( PTR ptr, UINT32 uiSize ) { if ( !fMemManagerInit ) DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFreeLocked: Warning -- Memory manager not initialized!!! ") ); if (ptr != NULL) { VirtualUnlock( ptr, uiSize ); VirtualFree( ptr, 0, MEM_RELEASE ); guiMemTotal -= uiSize; guiMemFreed += uiSize; } else { DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFreeLocked ERROR: NULL ptr received, size %d", uiSize) ); } // count even a NULL ptr as a MemFree, not because it's really a memory leak, but because it is still an error of some // sort (nobody should ever be freeing NULL pointers), and this will help in tracking it down if the above DbgMessage // is not noticed. MemDebugCounter--; #ifdef DEBUG_MEM_LEAKS DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemFreeLocked %p", ptr) ); #endif }
BOOLEAN IsSTCIETRLEFile( CHAR8 * ImageFile ) { HWFILE hFile; STCIHeader Header; UINT32 uiBytesRead; CHECKF( FileExists( ImageFile ) ); // Open the file and read the header hFile = FileOpen( ImageFile, FILE_ACCESS_READ, FALSE ); CHECKF( hFile ); if (!FileRead( hFile, &Header, STCI_HEADER_SIZE, &uiBytesRead ) || uiBytesRead != STCI_HEADER_SIZE || memcmp( Header.cID, STCI_ID_STRING, STCI_ID_LEN ) != 0 ) { DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem reading STCI header." ); FileClose( hFile ); return( FALSE ); } FileClose( hFile ); if (Header.fFlags & STCI_ETRLE_COMPRESSED) { return( TRUE ); } else { return( FALSE ); } }
PTR MemReallocReal( PTR ptr, UINT32 uiSize, const STR8 pcFile, INT32 iLine ) { PTR ptrNew; UINT32 uiOldSize = 0; if ( !fMemManagerInit ) DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemRealloc: Warning -- Memory manager not initialized -- Line %d in %s", iLine, pcFile) ); if(ptr != NULL) { uiOldSize = _msize(ptr); guiMemTotal -= uiOldSize; guiMemFreed += uiOldSize; MemDebugCounter--; } // Note that the ptr changes to ptrNew... ptrNew = _realloc_dbg( ptr, uiSize, _NORMAL_BLOCK, pcFile, iLine ); if (ptrNew == NULL) { DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemReAlloc failed: ptr %d, %d->%d bytes (line %d file %s)", ptr, uiOldSize, uiSize, iLine, pcFile) ); if ( uiSize != 0 ) { // ptr is left untouched, so undo the math above guiMemTotal += uiOldSize; guiMemFreed -= uiOldSize; MemDebugCounter++; } } else { #ifdef DEBUG_MEM_LEAKS DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemRealloc %p: Resizing %d bytes to %d bytes (line %d file %s) - New ptr %p", ptr, uiOldSize, uiSize, iLine, pcFile, ptrNew ) ); #endif guiMemTotal += uiSize; guiMemAlloced += uiSize; MemDebugCounter++; } return( ptrNew ); }
void Factory::AddSelectNode(GroupNode *pNode) { //check if group node is selectable if (pNode->IsSelectable()) { //add node to selectable node list DbgMessage("Adding selectable node %d: %s", pNode->GetSelectId(), pNode->GetName()); m_selectNodes[pNode->GetSelectId()] = pNode; } }
/* Desciption: * post slow path request of given type for given iscsi state * Assumptions: * - caller initialized request->type according to his specific request * - caller allocated space for request->data, according to the specific request type * - all previous slow path requests for given tcp state are already completed * Returns: * PENDING, SUCCESS or any failure */ lm_status_t lm_sc_post_slow_path_request( IN struct _lm_device_t *pdev, IN lm_iscsi_state_t *iscsi, IN lm_iscsi_slow_path_request_t *request) { lm_status_t lm_status = LM_STATUS_SUCCESS; u64_t data = 0; u8_t command = 0; DbgBreakIf(!(pdev && iscsi && request)); DbgMessage(pdev, VERBOSEl5sp, "### lm_sc_post_slow_path_request cid=%d, type=%d\n", iscsi->cid, request->type); switch (request->type) { /* NirV: called under lock, iscsi_state is being changed */ case SP_REQUEST_SC_INIT: lm_status = lm_sc_post_init_request(pdev, iscsi, request, &command, &data); break; case SP_REQUEST_SC_UPDATE: lm_status = lm_sc_post_update_request(pdev, iscsi, request, &command, &data); break; default: lm_status = LM_STATUS_FAILURE; DbgBreakMsg("Illegal slow path request type!\n"); break; } if (lm_status == LM_STATUS_PENDING) { DbgMessage(pdev, VERBOSEl5sp, "calling lm_command_post, cid=%d, command=%d, con_type=%d, data=%lx\n", iscsi->cid, command, ISCSI_CONNECTION_TYPE, data); lm_command_post(pdev, iscsi->cid, command, CMD_PRIORITY_NORMAL, ISCSI_CONNECTION_TYPE/*ulp*/, data); } request->status = lm_status; return lm_status; }
void diag (char *fmt, ...) { va_list args; char line[1024]; va_start (args, fmt); vsprintf (line, fmt, args); va_end (args); WinPaintChars (line, strlen (line), 0, 0); DbgMessage (line); SysTaskDelay (sysTicksPerSecond/4); }
UINT16 SetObjectHandleShade(UINT32 uiHandle, UINT32 uiShade) { HVOBJECT hObj; #ifdef _DEBUG gubVODebugCode = DEBUGSTR_SETOBJECTHANDLESHADE; #endif if(!GetVideoObject(&hObj, uiHandle)) { DbgMessage(TOPIC_VIDEOOBJECT, DBG_LEVEL_2, String("Invalid object handle for setting shade level")); return(FALSE); } return(SetObjectShade(hObj, uiShade)); }
BOOLEAN LoadImageData( HIMAGE hImage, UINT16 fContents ) { BOOLEAN fReturnVal = FALSE; Assert( hImage != NULL ); // Switch on file loader switch( hImage->iFileLoader ) { case TGA_FILE_READER: fReturnVal = LoadTGAFileToImage( hImage, fContents ); break; case PCX_FILE_READER: fReturnVal = LoadPCXFileToImage( hImage, fContents ); break; case STCI_FILE_READER: fReturnVal = LoadSTCIFileToImage( hImage, fContents ); break; default: DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_2, "Unknown image loader was specified." ); } if ( !fReturnVal ) { DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_2, "Error occured while reading image data." ); } return( fReturnVal ); }
static lm_status_t lm_sc_post_init_request( IN struct _lm_device_t *pdev, IN lm_iscsi_state_t *iscsi, IN lm_iscsi_slow_path_request_t *sp_req, OUT u8_t *command, OUT u64_t *data) { DbgMessage(pdev, VERBOSEl5sp, "##lm__post_initiate_offload_request\n"); DbgBreakIf(iscsi->hdr.status != STATE_STATUS_INIT_CONTEXT); *command = ISCSI_RAMROD_CMD_ID_INIT; *data = iscsi->ctx_phys.as_u64; return LM_STATUS_PENDING; }
void Factory::DeleteObjects() { DbgEnter(); if (!m_objects.empty()) { DbgMessage("%u objects", m_objects.size()); //delete all objects for (ObjectMap::iterator it = m_objects.begin(); it != m_objects.end(); it++) { delete it->second; } //clear object map m_objects.clear(); } }
UINT16 SetObjectShade(HVOBJECT pObj, UINT32 uiShade) { Assert(pObj!=NULL); Assert(uiShade >= 0); Assert(uiShade < HVOBJECT_SHADE_TABLES); if(pObj->pShades[uiShade]==NULL) { DbgMessage(TOPIC_VIDEOOBJECT, DBG_LEVEL_2, String("Attempt to set shade level to NULL table")); return(FALSE); } pObj->pShadeCurrent=pObj->pShades[uiShade]; return(TRUE); }
BOOLEAN CopyImageToBuffer( HIMAGE hImage, UINT32 fBufferType, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect ) { // Use blitter based on type of image Assert( hImage != NULL ); if ( hImage->ubBitDepth == 8 && fBufferType == BUFFER_8BPP ) { #ifndef NO_ZLIB_COMPRESSION if ( hImage->fFlags & IMAGE_COMPRESSED ) { DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_2, "Copying Compressed 8 BPP Imagery." ); return( Copy8BPPCompressedImageTo8BPPBuffer( hImage, pDestBuf, usDestWidth, usDestHeight, usX, usY, srcRect ) ); } #endif // Default do here DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_2, "Copying 8 BPP Imagery." ); return ( Copy8BPPImageTo8BPPBuffer( hImage, pDestBuf, usDestWidth, usDestHeight, usX, usY, srcRect ) ); } if ( hImage->ubBitDepth == 8 && fBufferType == BUFFER_16BPP ) { #ifndef NO_ZLIB_COMPRESSION if ( hImage->fFlags & IMAGE_COMPRESSED ) { DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Copying Compressed 8 BPP Imagery to 16BPP Buffer." ); return ( Copy8BPPCompressedImageTo16BPPBuffer( hImage, pDestBuf, usDestWidth, usDestHeight, usX, usY, srcRect ) ); } #endif // Default do here DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Copying 8 BPP Imagery to 16BPP Buffer." ); return ( Copy8BPPImageTo16BPPBuffer( hImage, pDestBuf, usDestWidth, usDestHeight, usX, usY, srcRect ) ); } if ( hImage->ubBitDepth == 16 && fBufferType == BUFFER_16BPP ) { #ifndef NO_ZLIB_COMPRESSION if ( hImage->fFlags & IMAGE_COMPRESSED ) { DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Automatically Copying Compressed 16 BPP Imagery." ); return( Copy16BPPCompressedImageTo16BPPBuffer( hImage, pDestBuf, usDestWidth, usDestHeight, usX, usY, srcRect ) ); } #endif DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Automatically Copying 16 BPP Imagery." ); return( Copy16BPPImageTo16BPPBuffer( hImage, pDestBuf, usDestWidth, usDestHeight, usX, usY, srcRect ) ); } return( FALSE ); }
lm_status_t lm_fc_init_fcoe_state( struct _lm_device_t *pdev, lm_state_block_t *state_blk, lm_fcoe_state_t *fcoe) { DbgMessage(pdev, VERBOSEl5sp, "###lm_fc_init_fcoe_state, ptr=%p\n", fcoe); DbgBreakIf(!(pdev && state_blk && fcoe)); fcoe->hdr.state_blk = state_blk; fcoe->hdr.state_id = STATE_ID_UNKNOWN; fcoe->hdr.status = STATE_STATUS_INIT; d_list_push_tail(&pdev->fcoe_info.run_time.fcoe_list, &fcoe->hdr.link); /* the rest of the fcoe state's fields that require initialization value other than 0, * will be initialized later (when lm_fc_init_fcoe_context is called) */ return LM_STATUS_SUCCESS; }
static lm_status_t lm_sc_post_update_request( IN struct _lm_device_t *pdev, IN lm_iscsi_state_t *iscsi, IN lm_iscsi_slow_path_request_t *sp_req, OUT u8_t *command, OUT u64_t *data) { struct protocol_common_spe spe = {0}; DbgMessage(pdev, VERBOSEl5sp, "##lm__post_initiate_offload_request\n"); DbgBreakIf(iscsi->hdr.status != STATE_STATUS_NORMAL); *command = ISCSI_RAMROD_CMD_ID_UPDATE_CONN; spe.data.phy_address.hi = iscsi->sp_req_data.phys_addr.as_u32.high; spe.data.phy_address.lo = iscsi->sp_req_data.phys_addr.as_u32.low; *data = *((u64_t*)(&(spe.data.phy_address))); return LM_STATUS_PENDING; }
/* Desciption: * initiate a caller allocated lm iscsi state * Assumptions: * - caller already zeroed given iscsi state * Returns: * SUCCESS or any failure */ lm_status_t lm_sc_init_iscsi_state( struct _lm_device_t *pdev, lm_state_block_t *state_blk, lm_iscsi_state_t *iscsi) { DbgMessage(pdev, VERBOSEl5sp, "###lm_sc_init_iscsi_state, ptr=%p\n", iscsi); DbgBreakIf(!(pdev && state_blk && iscsi)); iscsi->hdr.state_blk = state_blk; iscsi->hdr.state_id = STATE_ID_UNKNOWN; iscsi->hdr.status = STATE_STATUS_INIT; d_list_push_tail(&pdev->iscsi_info.run_time.iscsi_list, &iscsi->hdr.link); // NirV: sc: future statistics update /* the rest of the iscsi state's fields that require initialization value other than 0, * will be initialized later (when lm_sc_init_iscsi_context is called) */ return LM_STATUS_SUCCESS; }
bool Image::Save(cchar *szFile) { if (!szFile) { DbgError("Null file name!"); return false; } DbgMessage("Image %s", szFile); FILE *pFile = fopen(szFile, "wb"); if (!pFile) { DbgError("Unable to open file %s for writing!", szFile); return false; } bool success = Save(pFile); fclose(pFile); return success; }
/* clean up the lm_fcoe_state */ void lm_fc_del_fcoe_state( struct _lm_device_t *pdev, lm_fcoe_state_t *fcoe) { DbgMessage(pdev, VERBOSEl5sp, "###lm_fc_del_fcoe_state\n"); DbgBreakIf(!(pdev && fcoe)); /* DbgBreakIf(fcoe->hdr.status >= STATE_STATUS_OFFLOAD_PENDING && fcoe->hdr.status < STATE_STATUS_UPLOAD_DONE); */ /* remove the lm_fcoe_state from the state list */ d_list_remove_entry(&pdev->fcoe_info.run_time.fcoe_list, &fcoe->hdr.link); /* tcp->cid could have not been initialized if delete of state is a result of a failed initialization */ /* DbgBreakIf(fcoe->hdr.status != STATE_STATUS_UPLOAD_DONE && fcoe->hdr.status != STATE_STATUS_INIT_OFFLOAD_ERR); */ } /* lm_fc_del_fcoe_state */
/* Desciption: * delete iscsi state from lm _except_ from actual freeing of memory. * the task of freeing of memory is done in lm_sc_free_iscsi_state() * Assumptions: * global toe lock is taken by the caller */ void lm_sc_del_iscsi_state( struct _lm_device_t *pdev, lm_iscsi_state_t *iscsi) { u8_t notify_fw = 1; DbgMessage(pdev, VERBOSEl5sp, "###lm_sc_del_iscsi_state\n"); DbgBreakIf(!(pdev && iscsi)); DbgBreakIf(iscsi->hdr.status >= STATE_STATUS_OFFLOAD_PENDING && iscsi->hdr.status < STATE_STATUS_UPLOAD_DONE); /* just a moment before we delete this connection, lets take it's info... */ /*lm_tcp_collect_stats(pdev, tcp);*/ d_list_remove_entry( &pdev->iscsi_info.run_time.iscsi_list, &iscsi->hdr.link); /*pdev->iscsi_info.stats.total_upld++;*/ /* tcp->cid could have not been initialized if delete of state is a result of a failed initialization */ DbgBreakIf(iscsi->hdr.status != STATE_STATUS_UPLOAD_DONE && iscsi->hdr.status != STATE_STATUS_INIT_OFFLOAD_ERR); if (iscsi->hdr.status == STATE_STATUS_INIT_OFFLOAD_ERR) { notify_fw = 0; } lm_free_cid_resc(pdev, ISCSI_CONNECTION_TYPE, iscsi->cid, notify_fw); iscsi->hdr.state_blk = NULL; iscsi->cid = 0; iscsi->ctx_virt = NULL; iscsi->ctx_phys.as_u64 = 0; } /* lm_sc_del_iscsi_state */
void ShutdownMemoryManager( void ) { if ( MemDebugCounter != 0 ) { DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" ")); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****")); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****")); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****")); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" ")); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" >>>>> MEMORY LEAK DETECTED!!! <<<<< ")); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d memory blocks still allocated", MemDebugCounter )); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d bytes memory total STILL allocated", guiMemTotal )); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d bytes memory total was allocated", guiMemAlloced)); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d bytes memory total was freed", guiMemFreed)); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" ")); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****")); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****")); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****")); DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" ")); #ifndef EXTREME_MEMORY_DEBUGGING #ifdef JA2BETAVERSION { #ifndef USE_VFS FILE *fp; fp = fopen( "MemLeakInfo.txt", "a" ); if( fp ) { fprintf( fp, "\n\n" ); fprintf( fp, ">>>>> MEMORY LEAK DETECTED!!! <<<<<\n" ); fprintf( fp, " %d bytes memory total was allocated\n", guiMemAlloced ); fprintf( fp, "- %d bytes memory total was freed\n", guiMemFreed ); fprintf( fp, "_______________________________________________\n" ); fprintf( fp, "%d bytes memory total STILL allocated\n", guiMemTotal ); fprintf( fp, "%d memory blocks still allocated\n", MemDebugCounter ); fprintf( fp, "guiScreenExitedFrom = %S\n", gzJA2ScreenNames[ gMsgBox.uiExitScreen ] ); fprintf( fp, "\n\n" ); } fclose( fp ); #else sgp::Logger_ID log_id = sgp::Logger::instance().createLogger(); sgp::Logger::LogInstance memLeak = SGP_LOG(log_id); memLeak << sgp::endl << sgp::endl; memLeak << ">>>>> MEMORY LEAK DETECTED!!! <<<<<" << sgp::endl; memLeak << " " << guiMemAlloced << " bytes memory total was allocated" << sgp::endl; memLeak << "- " << guiMemFreed << " bytes memory total was freed" << sgp::endl; memLeak << "_______________________________________________" << sgp::endl; memLeak << guiMemTotal << " bytes memory total STILL allocated" << sgp::endl; memLeak << MemDebugCounter << " memory blocks still allocated" << sgp::endl; memLeak << "guiScreenExitedFrom = " << gzJA2ScreenNames[ gMsgBox.uiExitScreen ] << sgp::endl; memLeak << sgp::endl << sgp::endl; #endif } #endif #endif } UnRegisterDebugTopic( TOPIC_MEMORY_MANAGER, "Memory Manager Un-initialized" ); fMemManagerInit = FALSE; }
void _FailMessage(const char* message, unsigned lineNum, const char * functionName, const char* sourceFileName) { // This function shouldn't recurse static bool alreadyInThisFunction = false; if (alreadyInThisFunction) return; alreadyInThisFunction = true; sgp::dumpStackTrace(message); std::stringstream basicInformation; basicInformation << "Assertion Failure [Line " << lineNum; if (functionName) { basicInformation << " in function " << functionName; } basicInformation << " in file " << sourceFileName << "]"; std::stringstream outputString; outputString << "{ " << GetTickCount() << " } " << basicInformation.str(); //Build the output strings if( message ) sprintf( gubAssertString, message ); else sprintf( gubAssertString, "" ); //Output to debugger if (gfRecordToDebugger) OutputDebugString( outputString.str().c_str() ); DbgMessage( TOPIC_GAME, DBG_LEVEL_1, outputString.str().c_str()); //This will actually bring up a screen that prints out the assert message //until the user hits esc or alt-x. // WDS - Automatically try to save when an assertion failure occurs if (gGameExternalOptions.autoSaveOnAssertionFailure && !alreadySaving) { sprintf( gubErrorText, "%s. Attempting to do a debug save as SaveGame%d.sav (this may fail)", basicInformation.str().c_str(), SAVE__ASSERTION_FAILURE ); } else { sprintf( gubErrorText, "%s", basicInformation.str().c_str()); } SetPendingNewScreen( ERROR_SCREEN ); SetCurrentScreen( ERROR_SCREEN ); // WDS - Automatically try to save when an assertion failure occurs if (gGameExternalOptions.autoSaveOnAssertionFailure && !alreadySaving) { SaveGame( SAVE__ASSERTION_FAILURE, L"Assertion Failure Auto Save" ); } MSG Message; while (gfProgramIsRunning) { if (PeekMessage(&Message, NULL, 0, 0, PM_NOREMOVE)) { // We have a message on the WIN95 queue, let's get it if (!GetMessage(&Message, NULL, 0, 0)) { // It's quitting time continue; } // Ok, now that we have the message, let's handle it TranslateMessage(&Message); DispatchMessage(&Message); } else { // Windows hasn't processed any messages, therefore we handle the rest GameLoop(); gfSGPInputReceived = FALSE; } } alreadyInThisFunction = false; exit(0); }
void ErrDisplayFileLineMsg(const Char * const filename, UInt16 lineNo, const Char * const msg) { #if (EMULATION_LEVEL != EMULATION_NONE) StubErrDisplayFileLineMsg(filename, lineNo, msg); #else UInt16 fatalAlertResult; Char text[textBufferLen + 1]; SysEventType event; // Form the error message. Use PrvStrNCat everywhere to reduce the // number of utility routines we need to copy into this file. text[0] = '\0'; PrvStrNCat(text, filename, maxErrFilenameLen + 1); PrvStrNCat(text, ", Line:", textBufferLen + 1); StrIToA(text + StrLen(text), lineNo); PrvStrNCat(text, ", ", textBufferLen + 1); PrvStrNCat(text, msg, textBufferLen + 1); // If the UI has not been initialized yet, we can't put up an alert // so we'll force entry into the Debugger. // DOLATER kwk - shouldn't this check be in SysFatalAlert? Also // check for interrupt level; currently AMX kernal generates fatal // alert if 68K vector checksum has changed, but you can't safely // draw at that time. if (!(GSysMiscFlags & sysMiscFlagUIInitialized)) { GDbgWasEntered |= dbgEnteredFlagTrue; DbgBreak(); } // If the debugger was entered already, go to it if (GDbgWasEntered & dbgEnteredFlagTrue) { DbgMessage(text); DbgMessage("\n"); DbgBreak(); } // Else, show a fatal alert else { // If we re-entered, something terrible is wrong so just loop indefinitely so that // we don't eat up stack space. if (GSysMiscFlags & sysMiscFlagInFatalAlert) while(1) ; // Set flag to detect re-entry GSysMiscFlags |= sysMiscFlagInFatalAlert; // Display alert and reset if the first button (0) is pressed. if ( (fatalAlertResult = SysFatalAlert(text)) == fatalReset ) { #ifdef _DEBUG_ERROR_MGR DbgMessage("Reset Pressed\n"); #endif SysReset(); } // If the the second button(1) is pressed (can only happen with // full error checking on) go into Debugger. else if ( fatalAlertResult != fatalDoNothing ) { #ifdef _DEBUG_ERROR_MGR DbgMessage("Debug Pressed\n"); #endif DbgBreak(); } #ifdef _DEBUG_ERROR_MGR else DbgMessage("Continue Pressed\n"); #endif // Flush all events out. do { SysEventGet(&event, 1); } while (event.eType != nilEvent); // Clear re-entry detector GSysMiscFlags &= ~sysMiscFlagInFatalAlert; } #endif }
HVOBJECT CreateVideoObject( VOBJECT_DESC *VObjectDesc ) { HVOBJECT hVObject; HIMAGE hImage; ETRLEData TempETRLEData; // UINT32 count; // Allocate memory for video object data and initialize hVObject = MemAlloc( sizeof( SGPVObject ) ); CHECKF( hVObject != NULL ); memset( hVObject, 0, sizeof( SGPVObject ) ); // default of all members of the vobject is 0 // Check creation options // do // { if ( VObjectDesc->fCreateFlags & VOBJECT_CREATE_FROMFILE || VObjectDesc->fCreateFlags & VOBJECT_CREATE_FROMHIMAGE ) { if ( VObjectDesc->fCreateFlags & VOBJECT_CREATE_FROMFILE ) { // Create himage object from file hImage = CreateImage( VObjectDesc->ImageFile, IMAGE_ALLIMAGEDATA ); if ( hImage == NULL ) { MemFree( hVObject ); DbgMessage( TOPIC_VIDEOOBJECT, DBG_LEVEL_2, "Invalid Image Filename given" ); return( NULL ); } } else { // create video object from provided hImage hImage = VObjectDesc->hImage; if ( hImage == NULL ) { MemFree( hVObject ); DbgMessage( TOPIC_VIDEOOBJECT, DBG_LEVEL_2, "Invalid hImage pointer given" ); return( NULL ); } } // Check if returned himage is TRLE compressed - return error if not if ( ! (hImage->fFlags & IMAGE_TRLECOMPRESSED ) ) { MemFree( hVObject ); DbgMessage( TOPIC_VIDEOOBJECT, DBG_LEVEL_2, "Invalid Image format given." ); DestroyImage( hImage ); return( NULL ); } // Set values from himage hVObject->ubBitDepth = hImage->ubBitDepth; // Get TRLE data CHECKF( GetETRLEImageData( hImage, &TempETRLEData ) ); // Set values hVObject->usNumberOfObjects = TempETRLEData.usNumberOfObjects; hVObject->pETRLEObject = TempETRLEData.pETRLEObject; hVObject->pPixData = TempETRLEData.pPixData; hVObject->uiSizePixData = TempETRLEData.uiSizePixData; // Set palette from himage if ( hImage->ubBitDepth == 8 ) { hVObject->pShade8=ubColorTables[DEFAULT_SHADE_LEVEL]; hVObject->pGlow8=ubColorTables[0]; SetVideoObjectPalette( hVObject, hImage->pPalette ); } if ( VObjectDesc->fCreateFlags & VOBJECT_CREATE_FROMFILE ) { // Delete himage object DestroyImage( hImage ); } // break; } else { MemFree( hVObject ); DbgMessage( TOPIC_VIDEOOBJECT, DBG_LEVEL_2, "Invalid VObject creation flags given." ); return( NULL ); } // If here, no special options given, use structure given in paraneters // TO DO: // } // while( FALSE ); // All is well // DbgMessage( TOPIC_VIDEOOBJECT, DBG_LEVEL_3, String("Success in Creating Video Object" ) ); return( hVObject ); }
BOOLEAN ConvertVObjectRegionTo16BPP( HVOBJECT hVObject, UINT16 usRegionIndex, UINT8 ubShadeLevel ) { SixteenBPPObjectInfo * p16BPPObject; UINT8 * pInput; UINT8 * pOutput; UINT16 * p16BPPPalette; UINT32 uiDataLoop; UINT32 uiDataLength; UINT8 ubRunLoop; //UINT8 ubRunLength; INT8 bData; UINT32 uiLen; // check for existing 16BPP region and then allocate memory if (usRegionIndex >= hVObject->usNumberOfObjects || ubShadeLevel >= HVOBJECT_SHADE_TABLES) { return( FALSE ); } if (CheckFor16BPPRegion( hVObject, usRegionIndex, ubShadeLevel, NULL) == TRUE) { // it already exists; no need to do anything! return( TRUE ); } if (hVObject->usNumberOf16BPPObjects > 0) { // have to reallocate memory hVObject->p16BPPObject = MemRealloc( hVObject->p16BPPObject, sizeof( SixteenBPPObjectInfo ) * (hVObject->usNumberOf16BPPObjects + 1) ); } else { // allocate memory for the first 16BPPObject hVObject->p16BPPObject = MemAlloc( sizeof( SixteenBPPObjectInfo ) ); } if (hVObject->p16BPPObject == NULL) { hVObject->usNumberOf16BPPObjects = 0; return( FALSE ); } // the new object is the last one in the array p16BPPObject = &(hVObject->p16BPPObject[hVObject->usNumberOf16BPPObjects]); // need twice as much memory because of going from 8 to 16 bits p16BPPObject->p16BPPData = MemAlloc( hVObject->pETRLEObject[usRegionIndex].uiDataLength * 2 ); if (p16BPPObject->p16BPPData == NULL) { return( FALSE ); } p16BPPObject->usRegionIndex = usRegionIndex; p16BPPObject->ubShadeLevel = ubShadeLevel; p16BPPObject->usHeight = hVObject->pETRLEObject[ usRegionIndex ].usHeight; p16BPPObject->usWidth = hVObject->pETRLEObject[ usRegionIndex ].usWidth; p16BPPObject->sOffsetX=hVObject->pETRLEObject[ usRegionIndex ].sOffsetX; p16BPPObject->sOffsetY=hVObject->pETRLEObject[ usRegionIndex ].sOffsetY; // get the palette p16BPPPalette = hVObject->pShades[ubShadeLevel]; pInput = (UINT8 *) hVObject->pPixData + hVObject->pETRLEObject[ usRegionIndex ].uiDataOffset; uiDataLength=hVObject->pETRLEObject[usRegionIndex].uiDataLength; // now actually do the conversion uiLen=0; pOutput = (UINT8 *)p16BPPObject->p16BPPData; for (uiDataLoop = 0; uiDataLoop < uiDataLength; uiDataLoop++) { bData= *pInput; if(bData&0x80) { // transparent *pOutput = *pInput; pOutput++; pInput++; //uiDataLoop++; uiLen+=(UINT32)(bData&0x7f); } else if(bData > 0) { // nontransparent *pOutput = *pInput; pOutput++; pInput++; //uiDataLoop++; for(ubRunLoop=0; ubRunLoop < bData; ubRunLoop++) { *((UINT16 *)pOutput) = p16BPPPalette[*pInput]; pOutput++; pOutput++; pInput++; uiDataLoop++; } uiLen+=(UINT32)bData; } else { // eol *pOutput = *pInput; pOutput++; pInput++; //uiDataLoop++; if(uiLen!=p16BPPObject->usWidth) DbgMessage(TOPIC_VIDEOOBJECT, DBG_LEVEL_1, String( "Actual pixel width different from header width" )); uiLen=0; } // copy the run-length byte /* *pOutput = *pInput; pOutput++; if (((*pInput) & COMPRESS_TRANSPARENT) == 0 && *pInput > 0) { // non-transparent run; deal with the pixel data ubRunLoop = 0; ubRunLength = ((*pInput) & COMPRESS_RUN_LIMIT); // skip to the next input byte pInput++; for (ubRunLoop = 0; ubRunLoop < ubRunLength; ubRunLoop++) { *((UINT16 *)pOutput) = p16BPPPalette[*pInput]; // advance two bytes in output, one in input pOutput++; pOutput++; pInput++; uiDataLoop++; } } else { // transparent run or end of scanline; skip to the next input byte pInput++; } */ } hVObject->usNumberOf16BPPObjects++; return( TRUE ); }
void DbgNum(long l) { char buff[12]; StrPrintF(buff, "%ld", l); DbgMessage(buff); }
bool PngImage::Load(FILE *pStream) { if (pStream && !IsValid()) { bool success = false; ubyte aPngHeader[PNG_IMAGE_HEADER_SIZE]; png_structp pPngStruct = NULL; png_infop pPngInfo = NULL; //float gamma = 0.0; uint rowSize; ubyte *pImageData = NULL; png_bytep *pImageRows = NULL; uint offset = 0; png_uint_32 width = 0; png_uint_32 height = 0; int bpp = 0; int colorType = 0; //check png signature if (sizeof(aPngHeader) != fread(aPngHeader, 1, sizeof(aPngHeader), pStream)) { //read failed goto Exit_Load; } if (!png_check_sig(aPngHeader, sizeof(aPngHeader))) { //file is not a png image goto Exit_Load; } //create png read struct pPngStruct = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!pPngStruct) { //png struct allocation failed goto Exit_Load; } //create png info struct pPngInfo = png_create_info_struct(pPngStruct); if (!pPngInfo) { //png info allocation failed goto Exit_Load; } //required for png library use if (setjmp(pPngStruct->jmpbuf)) { //handle png read error goto Exit_Load; } //initialize png io png_init_io(pPngStruct, pStream); //set offset into the file since png header has been already read png_set_sig_bytes(pPngStruct, sizeof(aPngHeader)); //read png image info header png_read_info(pPngStruct, pPngInfo); png_get_IHDR(pPngStruct, pPngInfo, &width, &height, &bpp, &colorType, NULL, NULL, NULL); DbgMessage("Image %ux%ux%ubpp", width, height, bpp); //filter out unsupported images if (bpp < PNG_IMAGE_MIN_BPP || bpp > PNG_IMAGE_MAX_BPP) { goto Exit_Load; } //convert palette images to rgb if (PNG_COLOR_TYPE_PALETTE == colorType) { png_set_expand(pPngStruct); } //convert low-bpp images to 8 bpp if (bpp < IMAGE_BPP_8) { png_set_expand(pPngStruct); } //strip alpha channel if ((colorType & PNG_COLOR_MASK_ALPHA) || png_get_valid(pPngStruct, pPngInfo, PNG_INFO_tRNS)) { png_set_strip_alpha(pPngStruct); } //strip 16 bpp images down to 8 bpp if (IMAGE_BPP_16 == bpp) { png_set_strip_16(pPngStruct); } //convert grayscale images to rgb if (PNG_COLOR_TYPE_GRAY == colorType || PNG_COLOR_TYPE_GRAY_ALPHA == colorType) { //png_set_expand(pPngStruct); png_set_gray_to_rgb(pPngStruct); } //perform gamma correction if gamma is preset /*if (png_get_gAMA(pPngStruct, pPngInfo, &gamma)) { //png_set_gamma(pPngStruct, ???, gamma); }*/ //update image info png_read_update_info(pPngStruct, pPngInfo); //allocate space for image row offsets rowSize = png_get_rowbytes(pPngStruct, pPngInfo); pImageData = new ubyte [height * rowSize]; if (!pImageData) { //allocation failed goto Exit_Load; } //allocate space for image row pointers pImageRows = new png_bytep [height]; if (!pImageRows) { //allocation failed goto Exit_Load; } //set individual row pointers to correct offsets for (uint index = 0; index < height; ++index) { pImageRows[index] = pImageData + offset; offset += rowSize; } //read image data png_read_image(pPngStruct, pImageRows); png_read_end(pPngStruct, NULL); //set image properties m_pImageData = pImageData; m_width = static_cast<uint>(width); m_height = static_cast<uint>(height); m_bpp = static_cast<uint>(bpp); //image successfully loaded success = true; Exit_Load: delete pImageRows; if (pPngStruct && pPngInfo) { //free png struct and png info png_destroy_read_struct(&pPngStruct, &pPngInfo, NULL); } else if (pPngStruct) { //free png struct only png_destroy_read_struct(&pPngStruct, NULL, NULL); } if (!success) { delete pImageData; } return success; } return false; }
void DbgHex(unsigned long l) { char buff[12]; StrPrintF(buff, "0x%0lx", l); DbgMessage(buff); }