如果没有选中任何线型,GetItemDataPtr 会返回-1而不是0,getOIDSel 只判断了NULL,没有判断-1,故崩溃。
开发环境:Win10+VS2010+acad2014
arx的代码:
inline
AcDbObjectId
CAcUiLineTypeComboBox::getOIDSel(int sel)
{
AcDbObjectId oidLT;
CAcUiLTypeRecord* pLTRec =
(CAcUiLTypeRecord*)(GetItemDataPtr(sel));
if (NULL != pLTRec)
oidLT = pLTRec->objectId();
return oidLT;
}
修改的代码:
class CLineTypeComboBox : public CAcUiLineTypeComboBox
{
public:
AcDbObjectId
CLineTypeComboBox::getOIDSel(int sel)
{
AcDbObjectId oidLT;
CAcUiLTypeRecord* pLTRec =
(CAcUiLTypeRecord*)(GetItemDataPtr(sel));
if ( ( NULL != pLTRec ) && ( -1 != (int)pLTRec) )
oidLT = pLTRec->objectId();
return oidLT;
}
AcDbObjectId getOIDCurSel()
{
return getOIDSel(GetCurSel());
}
};

本文介绍了一个关于AutoCAD arx插件开发中出现的崩溃问题及其解决方案。问题出现在CAcUiLineTypeComboBox类的getOIDSel方法中,当未选择任何线型时,GetItemDataPtr返回-1导致程序崩溃。通过修改判断条件,确保pLTRec不为NULL且不等于-1,从而避免了崩溃情况。
2234

被折叠的 条评论
为什么被折叠?



