Topic: ConstructionSite::m_info lifetime
Kiscsirke Topic Opener |
Posted at: 2013-03-02, 23:14
So for now I'll post development questions here I'm still hunting down memory leaks, I found one that goes deep into unexplored territory in the code for me, so I'd like some advice So the problem is ConstructionSite::m_info, that is created here in the constructor, and then never deleted. Since ConstructionSite is noncopyable, I could just have m_info be a scoped_ptr, but I'm afraid the pointer could be used after the ConstructionSite itself is deleted. The pointer is asked for here, saved into the Fields "constructionsite" data field, and that is referenced later in GameRenderer::draw_objects() and in Map_Players_View_Data_Packet, that I guess could be accessed after the building is finished and the ConstructionSite object is deleted? (I've tried not to touch the Data Packet part of the code so far, seems a bit convoluted ) Also, now that I look, the same question could be asked of the Constructionsite_Information created in this line. Sooo, anyone who knows this part of the code could advise when these should be deleted? Or maybe just copy it by value everywhere (seems like a small class to me)? Top Quote |
Adamant |
Posted at: 2013-03-03, 03:21
nice job do you know to automatize your Job? nevertheless enjoy code.research. Ivan the Terrible is dead .. Genghis Khan is dead .. and I do not feel well, too. Top Quote |
ixprefect |
Posted at: 2013-03-03, 12:53
Hi Kiscsirke, I think that these should always be passed-by-value.
Top Quote |
Kiscsirke Topic Opener |
Posted at: 2013-03-03, 14:09
Okay, can do, except there is a place where It seems to be reading data written here. So can I just assume Anyway, that's what I'm trying now, but I'd feel safer if you confirmed Edit: Here's the change in code, can you take a look if it seems ok? Edited: 2013-03-03, 14:45
Top Quote |
ixprefect |
Posted at: 2013-03-03, 15:38
Yes, the whole "map objects on triangles" code is dead code that was never used in the first place. What you're seeing there are just some last remains that should be purged eventually. So I believe your changes to the view data packet are correct. However, please double-check the rediscover_node logic for players. There must be some place where the Field::constructionsite is zeroed (at least the .becomes and .was fields) when it is discovered that there is no longer a construction site on a field that was previously visible. Top Quote |
Kiscsirke Topic Opener |
Posted at: 2013-03-03, 19:38
Right, because it would've been zeroed out in the original code. Fixed here. I think it's correct now, thanks! Top Quote |