I got this Error upon return the following code. Anyone can tell me why and how to fix it please ? Thanks in advance
{
AcDbLayerTable* pLayerTbl = NULL;
acdbCurDwg()->getSymbolTable(pLayerTbl,AcDb::kForWrite);
AcDbLayerTableRecord* pBTR = new AcDbLayerTableRecord();
AcCmColor color;
int index;
acedInitGet(RSG_NONULL && RSG_NOZERO && RSG_NONEG, NULL);
acedGetInt(_T("\n Input layer color "), &index);
color.setColorIndex(index);
pBTR->setColor(color);
pBTR->close();
ACHAR name;
acedGetString(0,_T("\n Input layer name "), &name);
pBTR->setName(&name);
pLayerTbl->add(pBTR);
pBTR->close();
pLayerTbl->close();
}
Solved! Go to Solution.
Solved by owenwengerd. Go to Solution.
The 'name' buffer needs to have enough space to hold the entered string.
--
Owen Wengerd
ManuSoft
But there is not command like name.buffer nor name->buffer. How can i set the buffer long enough to solve this? Beside, this still crash even if the name i entered is 1 character long
The only one-character string is the empty string, because all C strings are null terminated.
To allocate name on the stack with a fixed size:
ACHAR name[134];
--
Owen Wengerd
ManuSoft
It is still not working thought :(. I have changed my code like you said, but the problem remain
My current code (the rest is unchanged š
// ....
ACHAR name[100];
acedGetString(0,_T("\n Input layer name "), &name[100]);
pBTR->setName(&name[100]);
// ....
You're sending a pointer to the last character in the allocated buffer, which makes it effectively a one-character buffer. Use all of the buffer, starting from the beginning (and note that a 100 character buffer is not large enough -- it must be at least 134):
ACHAR name[134];
acedGetString(0,_T("\n Input layer name "), name);
//need to check return value in case there was an error
pBTR->setName(name);
--
Owen Wengerd
ManuSoft
I came over this topic searching for a problem. And I noticed that you are first closing pBTR, then trying to change it! You should remove the first pBTR->close(); I think