LAPTOP-SNT8I5JK\Boounion
2025-06-21 088edcedd822070b6df3599aa87e08bea25a251d
1.修复CAttributeVector添加子项时类子项被另一个CAttributeVector释放造成内存失效闪退问题;
已修改4个文件
30 ■■■■ 文件已修改
SourceCode/Bond/Servo/CAttributeVector.cpp 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CAttributeVector.h 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CLoadPort.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CStep.cpp 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CAttributeVector.cpp
@@ -17,15 +17,15 @@
        m_attributes.clear();
    }
    void CAttributeVector::addAttribute(CAttribute* pAttribute, BOOL bReplace/* = FALSE*/)
    BOOL CAttributeVector::addAttribute(CAttribute* pAttribute, BOOL bReplace/* = FALSE*/)
    {
        if (!pAttribute) { 
            return;
            return FALSE;
        }
        const std::string& name = pAttribute->getName();
        if (name.empty()) { 
            return;
            return FALSE;
        }
        if (bReplace) {
@@ -41,6 +41,7 @@
        }
        m_attributes.push_back(pAttribute);
        return TRUE;
    }
    void CAttributeVector::addAttributeVector(CAttributeVector& av)
@@ -80,4 +81,9 @@
        ASSERT(index < m_attributes.size());
        return m_attributes[index];
    }
    std::vector<CAttribute*>& CAttributeVector::getAttributes()
    {
        return m_attributes;
    }
}
SourceCode/Bond/Servo/CAttributeVector.h
@@ -11,13 +11,14 @@
        virtual ~CAttributeVector();
    public:
        void addAttribute(CAttribute* pAttribute, BOOL bReplace = FALSE);
        BOOL addAttribute(CAttribute* pAttribute, BOOL bReplace = FALSE);
        void addAttributeVector(CAttributeVector& av);
        void clear();
        void sortWithWeight();
        unsigned int size();
        bool empty();
        CAttribute* getAttribute(unsigned int index);
        std::vector<CAttribute*>& getAttributes();
    private:
        std::vector<CAttribute*> m_attributes;
SourceCode/Bond/Servo/CLoadPort.cpp
@@ -300,7 +300,7 @@
            pStep->setName(pszName[m_nIndex]);
            pStep->setWriteSignalDev(0x128 + m_nIndex);
            pStep->setDataDev(dev[m_nIndex]);
            if (addStep(STEP_ID_PROT1_TYPE_AUTO_CHANGE_REPLY + m_nIndex, pStep) != 0) {
            if (addStep(STEP_ID_PROT1_CASSETTE_TYPE_CHANGE_REPLY + m_nIndex, pStep) != 0) {
                delete pStep;
            }
        }
SourceCode/Bond/Servo/CStep.cpp
@@ -94,9 +94,16 @@
    void CStep::addAttributeVector(CAttributeVector& attributeVector)
    {
        // 添加attribute时,要前删除存在的同名的attribute
        unsigned int size = attributeVector.size();
        for (unsigned int i = 0; i < size; i++) {
            m_attributeVector.addAttribute(attributeVector.getAttribute(i), TRUE);
        std::vector<CAttribute*>& srcs = attributeVector.getAttributes();
        auto it = srcs.begin();
        while (it != srcs.end()) {
            BOOL bAdd = m_attributeVector.addAttribute((*it), TRUE);
            if (bAdd) {
                it = srcs.erase(it);
            }
            else {
                ++it;
            }
        }
    }