Altering a lua-created class member yields strange behavior
Kristoffer Danielsson <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Inside LUA I do this:
mc = MyClass()
This object contains heavy, dynamically allocated, data, which I want to free at some point - inside C++.
I tried to keep track of all instances of MyClass inside C++, and then reset the data in all of them. The memory was freed, but I then got weird behavior in my script. (Note: Single-threaded application!)
// Stripped sample
class MyClass
{
public:
MyClass()
{
s_instances.insert(this);
}
virtual ~MyClass()
{
s_instances.erase(this);
}
static set<MyClass*> s_instances;
CData *pData;
};
Then, on a given signal, I deallocate pData for each MyClass object inside s_instances, and set the pointer to NULL. As already mentioned, this caused weird logical (!) problems inside my script when returning a table of MyClass pointers (luabind::newtable) and later issuing commands on the CData object (Proxy pattern here, the object is reallocated when used. The sample code is somewhat simplified.).
Any ideas, or is this an error on my side?
Thanks.
_________________________________________________________________
Vi vet vem du passar ihop med! Klicka här för att få veta!
http://dejting.se.msn.com/channel/index.aspx?trackingid=1002952
------------------------------------------------------------------------------
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user