明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1933|回复: 1

[ARX]向当前数据库插入图块代码,有点问题,内存泄漏,各位看看

[复制链接]
发表于 2005-4-16 15:18:00 | 显示全部楼层 |阅读模式
void Hyd_insertBlock2Cur(AcDbDatabase* pSourceDb,CString blockName)
{

CMemoryState oldMemState, newMemState, diffMemState;
oldMemState.Checkpoint();
acDocManager->lockDocument(acDocManager->curDocument()); //写当前数据库之前一定要锁定
AcDbBlockTable* pSoureTable=NULL;
AcDbObjectId idBlock;
pSourceDb->getSymbolTable(pSoureTable, AcDb::kForRead);

if (pSoureTable->getAt(blockName,idBlock)== Acad::eOk)//指定文件找到块
{
pSoureTable->close();
AcDbDatabase * pOutputDb = new AcDbDatabase(Adesk::kTrue);
pSourceDb->wblock(pOutputDb, idBlock);
if (acdbCurDwg()->insert(idBlock,blockName,pOutputDb,true) != Acad::eOk)
{
delete pOutputDb;
pOutputDb=NULL;
return ;
}
delete pOutputDb;
pOutputDb=NULL;

AcDbBlockTableRecord* pMODELSPACE = NULL;
AcDbBlockTable* pCurBlockTable=NULL;
if (acdbCurDwg()->getSymbolTable(pCurBlockTable, AcDb::kForRead)!=Acad::eOk)
{

return ;
}
if (pCurBlockTable->getAt(ACDB_MODEL_SPACE,pMODELSPACE,AcDb::kForWrite)!=Acad::eOk)
{
pCurBlockTable->close();
return ;
}
if (pCurBlockTable->getAt(blockName,idBlock)!=Acad::eOk)
{
pCurBlockTable->close();
pMODELSPACE->close();
return ;
}
pCurBlockTable->close(); AcGeScale3d scale;
scale[X]=1;
scale[Y]=1;
scale[Z]=1;

AcGePoint3d basePoint;
int retCode; acedInitGet(NULL, NULL);
acedAlert("选择插入点!");
retCode = acedGetPoint(NULL, NULL,asDblArray(basePoint));
switch(retCode)
{
case RTCAN :
case RTNONE :
basePoint.set(0.0, 0.0, 0.0);
break;
case RTNORM :
break;
case RTERROR :
break;
}


AcDbBlockReference *pBR = new AcDbBlockReference;
pBR->setBlockTableRecord(idBlock);
pBR->setPosition(basePoint);
pBR->setRotation(0);
pBR->setScaleFactors(scale);
if (pMODELSPACE->appendAcDbEntity(pBR)!=Acad::eOk)
{
delete pBR;
pMODELSPACE->close();
return ;
}
pBR->close();
pMODELSPACE->close();
}
else
pSoureTable->close();

acDocManager->unlockDocument(acDocManager->curDocument()); //解除锁定
TRACE0("\n\ninsert is finishing!!\n\n");

newMemState.Checkpoint();
if( diffMemState.Difference( oldMemState, newMemState ) )
{
TRACE( "Memory leaked!\n" );
}
// 输出内存泄漏报告,显示在 Output 窗口的 Debug 页中
_CrtDumpMemoryLeaks(); } 我自己实在是检查不出来了。在CAD中反复操作插入图块都是好的,可是一关掉CAD,等一会就跳出了一个警告框了。估计是CAD关掉后,清理内存时,有申请的内存没有卸载掉的,各位帮忙看看吧
发表于 2005-4-19 15:34:00 | 显示全部楼层
昏..多半是因为你用memory check的原因..我的意思是内存泄漏是由内存检查本身的存在引起的..因为release build对debug build兼容不好..


ACAD软件本身是release build, 所以ARX也要尽量用release build, 避免不必要的debug和release不兼容的麻烦..
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 06:39 , Processed in 0.147406 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表