when I create three million AcDbText and add them to model space, in this process, AutoCAD show fatal error warning, then AutoCAD collapse.
why?, what can i do for this?
BOOL AddToModelSpace(AcDbEntity *pEnt)
{
if(pEnt == NULL)
return FALSE;
AcDbBlockTable *pTable = NULL;
Acad::ErrorStatus es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pTable, AcDb::kForRead);
AcDbBlockTableRecord *pRecd = NULL;
es = pTable->getAt(ACDB_MODEL_SPACE, pRecd, AcDb::kForWrite);
es = pRecd->appendAcDbEntity(pEnt);
pTable->close();
pRecd->close();
pEnt->close();
return TRUE;
}
void cmdTest()
{
for(long m=0L; m<1500L; m++){
for(long j=0L; j<2000L; j++){
AcDbText *pText = new AcDbText(AcGePoint3d(m*100,j*100,0), _T("abc"));
pText->setColorIndex(1);
if(AddToModelSpace(pText)==FALSE){
if(pText != NULL)
delete pText;
}
}
}
}
your code works fine, BUT...
when it was done 86%, I got a message, that I have not enough memory to complete task.
So, I think that your computer is not good enough for this task such as my 🙂
PS: I didn't got a fatal error at all
AcApDocument * pDoc = acDocManager->mdiActiveDocument(); acDocManager->lockDocument(pDoc); acedSetStatusBarProgressMeter(_T("Press ESC to abort: "), 0, 1500); for(long m=0L; m<1500L; m++) { for(long j=0L; j<2000L; j++) { AcDbText *pText = new AcDbText(AcGePoint3d(m*100,j*100,0), _T("abc")); pText->setColorIndex(1); if(AddToModelSpace(pText)==FALSE) { if(pText != NULL) delete pText; } } acedSetStatusBarProgressMeterPos( m ); if(acad_abortCycle(_T("\nINFO: aborted...")) == 1) break; } acedRestoreStatusBar(); acDocManager->unlockDocument(pDoc);
int acad_abortCycle(const ACHAR * abortString) { int res = 0; CWinApp *app = acedGetAcadWinApp(); CWnd *wnd = app->GetMainWnd (); MSG msg; while (:: PeekMessage (&msg, wnd->m_hWnd, 0, 0, PM_NOREMOVE)) { if (!app->PumpMessage()) { :: PostQuitMessage(0); break; } } LONG lIdle = 0; while (app->OnIdle (lIdle++)); res = acedUsrBrk(); if(res == 1 && abortString != NULL) acutPrintf(abortString); return res; }
2GB.
But free memory, that can be used is little more then 1.2GB (Windows, antivirus, e.t.c eat 800MB)
Hi,
try to turn off UNDO-recording, that will save a lot of memory as AutoCAD does not need to save every single add-task.
_UNDO _AUTO _OFF
- alfred -
when it was done 59%, I got a fatal error message .
if I stop at 58%, then all AcDbText are created in model space, But if click "ZOOM" or "REGEN" in command line, AutoCAD show fatal error and collapse. It looks like refresh graphics display make it.
did you test this in pure autocad? if no, try to unload everything additional (arx-files, lisp and so on) and leave just pure acad, like after installation. I didn't get fatal error. It was a messagebox with Ok|Cancel buttons for aborting the task. So, the problem can be in other arx file :), if it has, db reactor, for example.
And what about Alfred's advice? It will reduce the memory usage.
PS: try to do the same with, for example, points or lines (to check is this text bug or just lack of memory)
PS: if it was a pure autocad, may be it's time to reinstall it 🙂
in pure autocad, it outputs more AcDbText, but cmmand "zoom" and "regen" still lead to error or enough memory .
turn off UNDO-recording, not solve the problem.
points or lines has no problem.
It looks like lack of memory, I'm not sure.
sorry for previous empty reply.
put the open and close BlockTable operations inside the loop is not a good idea.those operations costly. you should put those codes outside the loop,my suggestion may not the right answer,but it's worth to try.