AcDbBlockTableRecord::getBlockReferenceIds(AcDbObjectIdArray entity_array)은 항상 예외를 발생시킨다

AcDbBlockTableRecord::getBlockReferenceIds(AcDbObjectIdArray entity_array)은 항상 예외를 발생시킨다

yang8570
Enthusiast Enthusiast
833 Views
6 Replies
Message 1 of 7

AcDbBlockTableRecord::getBlockReferenceIds(AcDbObjectIdArray entity_array)은 항상 예외를 발생시킨다

yang8570
Enthusiast
Enthusiast

나는 AcDbObjectIdArray  이 소멸자가 실행할때마다 예외가 발생한다.

다른곳에서는 AcDbObjectIdArray  전혀 문제 없이 사용하고 있다..

하지만 AcDbBlockTableRecord::getBlockReferences 이곳에서 사용한 AcDbObjectIdArray  은 항상 예외를 발생시킨다

머리가 터지기 직전입니다.

좀 도와주세요

 

0 Likes
Accepted solutions (2)
834 Views
6 Replies
Replies (6)
Message 2 of 7

tbrammer
Advisor
Advisor

I think you mean

Acad::ErrorStatus AcDbBlockTableRecord::getBlockReferenceIds(AcDbObjectIdArray& ids, bool bDirectOnly = true, bool bForceValidity = false) const;

Is your AcDbBlockTableRecord opened for read?
Is the function called within the main thread? ARX isn't thread safe!
Coud it be that the AcDbObjectIdArray 's memory was "damaged" somehow? Check whether the AcDbObjectIds in the array are valid before the AcDbObjectIdArray is released.

Can you post a small sample project or at least a code sample that causes the crash to happen?


Thomas Brammer ● Software Developer ● imos AG ● LinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 3 of 7

yang8570
Enthusiast
Enthusiast
//블럭을 선택 하면 블럭안에 존재하는 치수관련된 항목의  pEnt->setVisibility(AcDb::Visibility::kInvisible);   를 토글시켜주는 명령입니다.새 비트맵 이미지.jpg
 
 
아래의 코드는 항상 끝까지 실행 합니다.
하지만 이렇게 es = pRcd->getBlockReferenceIds(ids);
AcDbObjectIdArray를 사용하고 나면은 항상 이래서 
AcDbObjectIdArray *ids = new AcDbObjectIdArray;
메모리 해제를 하지 않고 사용하고 있습니다.
 
다른것에서 AcDbObjectIdArray를 사용할때는 큰 문제가 없는데 유독
AcDbBlockTableRecord* pRcd;에서 
es = pRcd->getBlockReferenceIds(ids);이렇게 사용하고 난 뒤에는 항상 예외를 발생 합니다.
 
함수가 메인 스레드 내에서 호출되나요?<------따로 스레드를  만들지는 않았습니다.
오토캐드는 스레드를 하나만 사용한다고 들었습니다.
 
혹시 AcDbObjectIdArray의 메모리가 어떤 식으로든 "손상"된 걸까요? AcDbObjectIdArray를 해제하기 전에 배열의 AcDbObjectId가 유효한지 확인하세요.
 
AcDbObjectId가 유효한지 확인하세요.<-----어떻게 하는지를  모릅니다.
 
 
 
 
//블럭속에 포함된 항목중에서 치수항목만 보이기를 토글시켜준다.
void vsfblockDimToggle1() {
AcDbBlockReference * pBR = getBR();//블럭레퍼런스를 선택합니다.
if (pBR == NULL) return;
 
AcDbObjectId blockTableRecordId = pBR->blockTableRecord();
if (pBR)pBR->close();
 
AcDbBlockTableRecord* pRcd;
Acad::ErrorStatus es = acdbOpenObject(pRcd, blockTableRecordId, AcDb::kForRead);
 
AcDbBlockTableRecordIterator* pIter = NULL;
es = pRcd->newIterator(pIter);
if (Acad::eOk != es) { if (pRcd)pRcd->close(); return; }
 
for (pIter->start(); !pIter->done(); pIter->step()) {
AcDbEntity* pEnt = NULL;
es = pIter->getEntity(pEnt,  AcDb::kForRead);
if (Acad::eOk != es) {
if (pEnt != NULL)pEnt->close();
continue;
}
 
if (isDimEntity(pEnt)) {//엔티티가 치수관련항목인지를 확인하여 참,거짓만 답변함.
es = pEnt->upgradeOpen();
if (es != Acad::eOk) {
if (pEnt != NULL)pEnt->close();
continue;
}
 
AcDb::Visibility vstate = pEnt->visibility();
if (vstate == AcDb::Visibility::kVisible) {
es = pEnt->setVisibility(AcDb::Visibility::kInvisible);
if (es != Acad::eOk) {
if (pEnt != NULL)pEnt->close();
continue;
}
}
else {
es = pEnt->setVisibility(AcDb::Visibility::kVisible);
if (es != Acad::eOk) {
if (pEnt != NULL)pEnt->close();
continue;
}
}
pEnt->downgradeOpen();
pEnt->close();
}
if (pEnt) { pEnt->close();/* pEnt=NULL;*/ }
}
 
AcDbObjectIdArray ids;// = new AcDbObjectIdArray;
es = pRcd->getBlockReferenceIds(ids);
if (pRcd)pRcd->close();
delete pIter;
blockRefUpdate(ids);
return;//디버그시 여기까지는 문제가 없읍니다.
}
 
 
0 Likes
Message 4 of 7

tbrammer
Advisor
Advisor

I don't see any issues in the code you posted. 

The code you posted is not complete. The functions getBR(), blockRefUpdate(ids), isDimEntity(pEnt) are missing.

Furthermore your comment

return; //There are no problems up to this point during debugging..

shows that it doesn't even throw an exception.

Please provide buildable code that allows to reproduce the problem.

At which point is the exeption thrown? And what kind of exeption is it? Can you continue debugging after it was thrown?

 

 

 

 

 


Thomas Brammer ● Software Developer ● imos AG ● LinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 5 of 7

yang8570
Enthusiast
Enthusiast

tbrammer당신의 관심에 대하여 정말 감사의 마음을 전합니다.

나는 혼자서 독학으로 autocad,lisp,visual c++까지 공부를 해서 다른 사람들과 같이 이것에 대하여 조언을 받아본 적이 없습니다.

블로그나 이런 곳들을 찾아 다니면서 프로그램을 혼자서 만들었습니다..내가 직접짠 코드가 대략 10만라인정도의 분량입니다.

그래서 나는 내가 뭐가 부족한지  잘못된 코딩습관이 있는지 조차도 스스로 생각을 하지 못하는 상태이다.

다행이 프로그램을 만들어서 사용하는데 큰 문제 없이 잘 사용은 하고 있는중입니다.

하지만 아직 해결하지 못한것중에 하나가 지금의 이 주제입니다.

다시한번 감사의 인사를 드립니다.

 

shows that it doesn't even throw an exception.

Please provide buildable code that allows to reproduce the problem.

At which point is the exeption thrown? And what kind of exeption is it?<----  AcDbObjectIdArray 의 소멸자를 호출하면서 예외를 발생시킴니다.

Can you continue debugging after it was thrown?<-----디버그는 더이상 불가합니다.

 

 

 

 

 

 

AcDbBlockReference * getBR(void) {
AcDbBlockReference *pEnt = NULL;
ads_name en;
ads_point pt;
if (acedEntSel(ACRX_T("\nSelect a BlockReference :"), en, pt) != RTNORM){
acedSSFree(en);
return pEnt;
}

AcDbObjectId entId = AcDbObjectId::kNull;
Acad::ErrorStatus es;
es = acdbGetObjectId(entId, en);
if (es != Acad::eOk) {
// Alert2(L"23 es: %d", es);
acedSSFree(en); return pEnt; }

es = acdbOpenObject(pEnt, entId, AcDb::kForRead);
if (es != Acad::eOk) {
if (pEnt) {
pEnt->close();
pEnt = NULL;
}
acedSSFree(en);
return pEnt;
}

if (pEnt->isA() != AcDbBlockReference::desc()) {
acutPrintf(ACRX_T("\n Please select a BlockReference."));
if (pEnt) {
pEnt->close();
pEnt = NULL;
}
acedSSFree(en);
return pEnt;
}
acedSSFree(en);
return pEnt;
}

 

bool isDimEntity(AcDbEntity *pEnt) {
return (pEnt->isA() == (AcDbDimension::desc()) ||
pEnt->isA() == (AcDbOrdinateDimension::desc()) ||
pEnt->isA() == (AcDbAlignedDimension::desc()) ||
pEnt->isA() == (AcDbRotatedDimension::desc()) ||
pEnt->isA() == (AcDb3PointAngularDimension::desc()) ||
pEnt->isA() == (AcDb2LineAngularDimension::desc()) ||
pEnt->isA() == (AcDbRadialDimension::desc()) ||
pEnt->isA() == (AcDbDiametricDimension::desc()) ||
pEnt->isA() == (AcDbArcDimension::desc()) ||
pEnt->isA() == (AcDbRadialDimensionLarge::desc()));
}
 

 

 

void blockRefUpdate(AcDbObjectIdArray ids) {
AcDbObjectId refId;
AcDbEntity* pObject = NULL;
Acad::ErrorStatus es;
for (int m = 0; m < ids.length(); m++) {
refId = ids.at(m);
es = acdbOpenObject(pObject, refId, AcDb::kForWrite);
if (Acad::eOk != es)
if (Acad::eOk != es) {
if (pObject) {pObject->close(); pObject = NULL;}
//Alert2(L"27  es: %d", es);
continue;
}
 
pObject->assertWriteEnabled();
es = pObject->close();
pObject = NULL;
}
}
0 Likes
Message 6 of 7

tbrammer
Advisor
Advisor
Accepted solution

There are some issues in your code:

	if (acedEntSel(ACRX_T("\nSelect a BlockReference :"), en, pt) != RTNORM)
	{ 
		acedSSFree(en);  // NO! en is not a selection set!
		return pEnt; 
	} 

ARX uses ads_name for single entities as in your code and for selection sets which are selected using acedSSGet().
Only ads_name s of selection sets must be releases with acedSSFree(en)!

Calling acedSSFree(en) for a single entity ads_name might cause problems.

You call it at several places in the code. Just remove all these calls. A single entity ads_name must not be freed.

 

// Your code for isDimEntity(pEnt) works. 
// But it is much shorter an easier to check this way:
bool isDimEntity(AcDbEntity *pEnt) {   
   return (AcDbDimension::cast(pEnt) != nullptr);
}
// All dim classes like AcDbAlignedDimension are derived from AcDbDimension

 

You haven't yet posted a complete code sample that leads to the crash. So I can't reproduce the problem.
You wrote (Google translated):

"I am using it without freeing the memory because of this:
AcDbObjectIdArray *ids = new AcDbObjectIdArray;"

Not sure whether this is translated correctly. 

If you create the AcDbObjectIdArray with new like this, you should also destroy it with delete ids; ids=nullptr; 

otherwise you will get memory leaks.


Thomas Brammer ● Software Developer ● imos AG ● LinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 7 of 7

yang8570
Enthusiast
Enthusiast
Accepted solution

ARX uses ads_name for single entities as in your code and for selection sets which are selected using acedSSGet().
Only ads_name s of selection sets must be releases with acedSSFree(en)!

Calling acedSSFree(en) for a single entity ads_name might cause problems.

You call it at several places in the code. Just remove all these calls. A single entity ads_name must not be freed.

 

나는 항상 ads_name 를  acedSSFree(en)로 해제를 했습니다.

single entities  and selection sets

이것이 문제인것 같습니다.

문제가 해결이 되었습니다.

나는 전체 코드에서 single entities  ads_name 를  acedSSFree(en)로 해제한 코드를 수정하여야겠습니다.

감사합니다.

 

0 Likes