gpt4 book ai didi

c++ - 奇怪的堆损坏问题?

转载 作者:太空宇宙 更新时间:2023-11-04 11:58:12 25 4
gpt4 key购买 nike

<分区>

出于某种原因,我从以下类定义文件中得到了一个奇怪的堆损坏,很可能是在“CreateFromNode”函数中。谁能帮我这个?自从我发现它后,我真的很想现在就处理它,而不是看到它在以后出现。此外,没有外部力量正在修改此类的任何成员(或其成员)。

#include "Object.h"

TmxMap::Object::Object():name(), position(), size(), gid(-1), visible(true),
properties(), image(), polygon(NULL), polyline(NULL), ellipse(false){}

TmxMap::Object::Object(rapidxml::xml_node<>* const& object_node):name(),
position(), size(), gid(-1), visible(true), properties(), image(),
polygon(NULL), polyline(NULL), ellipse(false){
CreateFromNode(object_node);
}

TmxMap::Object::Object(TmxMap::Object const& from):name(from.name),
position(from.position), size(from.size), gid(from.gid),
visible(from.visible), properties(from.properties),
image(from.image), polygon(from.polygon), polyline(from.polyline),
ellipse(from.ellipse){}

TmxMap::Object::~Object(){
DeleteObjects();
}

void TmxMap::Object::CreateFromNode(rapidxml::xml_node<>* const& object_node){
DeleteObjects();

rapidxml::xml_node<>* data_node = NULL;
rapidxml::xml_attribute<>* data_attrib = NULL;

if((data_attrib = object_node -> first_attribute("name")))
name = data_attrib -> value();

if((data_attrib = object_node -> first_attribute("width")))
size.x = std::strtol(data_attrib -> value(), NULL, 10);
if((data_attrib = object_node -> first_attribute("height")))
size.y = std::strtol(data_attrib -> value(), NULL, 10);

position.Set(
std::strtol(object_node -> first_attribute("x") -> value(), NULL, 10),
std::strtol(object_node -> first_attribute("y") -> value(), NULL, 10)
);

if((data_node = object_node -> first_node("polygon")))
polygon = new Polygon2D<int>(data_node);

if((data_node = object_node -> first_node("polyline")))
polyline = new Polyline2D<int>(data_node);

ellipse = (object_node -> first_node("ellipse") != NULL);
}

void TmxMap::Object::DeleteObjects(){
if(polygon){delete polygon; polygon = NULL;}
if(polyline){delete polyline; polyline = NULL;}
}

void TmxMap::Object::Destroy(){
name.clear();
position.Set();
size.Set();
gid = 0;
visible = true;
properties.Destroy();
image.Destroy();
DeleteObjects();
ellipse = false;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com