[ARX]向当前数据库插入图块代码,有点问题,内存泄漏,各位看看
void Hyd_insertBlock2Cur(AcDbDatabase* pSourceDb,CString blockName)<BR>{<BR> <BR> CMemoryState oldMemState, newMemState, diffMemState;<BR> oldMemState.Checkpoint();<BR> acDocManager->lockDocument(acDocManager->curDocument()); //写当前数据库之前一定要锁定<BR> AcDbBlockTable* pSoureTable=NULL;<BR> AcDbObjectId idBlock;<BR> pSourceDb->getSymbolTable(pSoureTable, AcDb::kForRead);<BR> <BR> if (pSoureTable->getAt(blockName,idBlock)== Acad::eOk)//指定文件找到块<BR> {<BR> pSoureTable->close();<BR> AcDbDatabase * pOutputDb = new AcDbDatabase(Adesk::kTrue);<BR> pSourceDb->wblock(pOutputDb, idBlock);<BR> if (acdbCurDwg()->insert(idBlock,blockName,pOutputDb,true) != Acad::eOk)<BR> {<BR> delete pOutputDb;<BR> pOutputDb=NULL;<BR> return ;<BR> }<BR> delete pOutputDb;<BR> pOutputDb=NULL;<BR> <BR> AcDbBlockTableRecord* pMODELSPACE = NULL;<BR> AcDbBlockTable* pCurBlockTable=NULL;<BR> if (acdbCurDwg()->getSymbolTable(pCurBlockTable, AcDb::kForRead)!=Acad::eOk)<BR> {<BR> <BR> return ;<BR> }<BR> if (pCurBlockTable->getAt(ACDB_MODEL_SPACE,pMODELSPACE,AcDb::kForWrite)!=Acad::eOk)<BR> {<BR> pCurBlockTable->close();<BR> return ;<BR> }<BR> if (pCurBlockTable->getAt(blockName,idBlock)!=Acad::eOk)<BR> {<BR> pCurBlockTable->close();<BR> pMODELSPACE->close();<BR> return ;<BR> }<BR> pCurBlockTable->close();AcGeScale3d scale;<BR> scale=1;<BR> scale=1;<BR> scale=1;<BR> <BR> AcGePoint3d basePoint;<BR> int retCode;
acedInitGet(NULL, NULL);<BR> acedAlert("选择插入点!");<BR> retCode = acedGetPoint(NULL, NULL,asDblArray(basePoint));<BR> switch(retCode)<BR> {<BR> case RTCAN :<BR> case RTNONE :<BR> basePoint.set(0.0, 0.0, 0.0);<BR> break;<BR> case RTNORM :<BR> break;<BR> case RTERROR : <BR> break;<BR> }<BR> <BR> <BR> AcDbBlockReference *pBR = new AcDbBlockReference;<BR> pBR->setBlockTableRecord(idBlock);<BR> pBR->setPosition(basePoint);<BR> pBR->setRotation(0); <BR> pBR->setScaleFactors(scale);<BR> if (pMODELSPACE->appendAcDbEntity(pBR)!=Acad::eOk)<BR> {<BR> delete pBR;<BR> pMODELSPACE->close();<BR> return ;<BR> }<BR> pBR->close();<BR> pMODELSPACE->close();<BR> }<BR> else<BR> pSoureTable->close();<BR> <BR> acDocManager->unlockDocument(acDocManager->curDocument()); //解除锁定<BR> TRACE0("\n\ninsert is finishing!!\n\n");<BR> <BR> newMemState.Checkpoint();<BR> if( diffMemState.Difference( oldMemState, newMemState ) )<BR> {<BR> TRACE( "Memory leaked!\n" );<BR> }<BR> // 输出内存泄漏报告,显示在 Output 窗口的 Debug 页中<BR> _CrtDumpMemoryLeaks();
}
我自己实在是检查不出来了。在CAD中反复操作插入图块都是好的,可是一关掉CAD,等一会就跳出了一个警告框了。估计是CAD关掉后,清理内存时,有申请的内存没有卸载掉的,各位帮忙看看吧 昏..多半是因为你用memory check的原因..我的意思是内存泄漏是由内存检查本身的存在引起的..因为release build对debug build兼容不好..
ACAD软件本身是release build, 所以ARX也要尽量用release build, 避免不必要的debug和release不兼容的麻烦..
页:
[1]