API improvements: Group references python api, for better control over groups and instances
Closed, ResolvedPublic


This patch is an API extension for KX_GameObject class, that allows the user to gain better control over group instances at runtime. At level creation time, the user have to work with empty objects (proxies) for the grouped objects, but at runtime the proxy creates the whole group instances.

The problem:
There is no connection between the group proxy and the instanced objects. The patch provides two new read-only properties for KX_GameObject's, so you can easily access all instanced objects from the group empty, or you can access the group proxy from an instanced object.

For more informations you can checkout the complete proposal:

The files for testing this feature and for showing some possibilities:




I am not sure how you created your patch, but I had to tweak the file a little to get it to apply right.

More importantly though, if you edit the python API make sure to edit the docs corresponding to that part of the API. This is doable in the appropriate rst file in the doc/python_api folder.

There is a memory leak: KX_GameObject::m_pInstanceObjects is never cleaned up.

Okay, I've uploaded a version of the patch with better refcounting. Visual Leak Detector is not reporting any more leaks with this version. :)

I just noticed that you have added some KX_PYMETHODs in KX_GameObject.h that are never actually getting used, and can be removed.

Looks like the improved patch can still cause leaks with replica objects. Some additional processing might have to be done in KX_GameObject::GetReplica().

Your patch causes a zombie object for every group proxy, that is deleted.
I have added a check for group objects in newDeleteObject():
If the group object is deleted, all members should loose their reference to the group object.

+ if(newobj->GetInstanceObjects()) {
+ for (int i = 0; i < newobj->GetInstanceObjects()->GetCount(); i++) {
+ KX_GameObject* instance = (KX_GameObject*)newobj->GetInstanceObjects()->GetValue(i);
+ instance->RemoveDupliGroupObject();
+ }
+ }

I still have some stuff to cleanup, an assertion is not needed in RemoveDupliGroupObject() and I will also cleanup the KX_PYMETHODs.

Tried to upload, the patch, did not work the first time..

I've been using this patch quite a bit in my current game project, and I'm not getting any more zombie objects. I'm attaching the copy of the patch that I've been using. It's mostly the same as Martin's last patch, but I've removed an assert (it was right in front of a NULL check anyways), and I made the patch with TortoiseSVN.

I'm assigning this to Campbell for final review/okay.

Thanks for your support, Mitchell!

This patch has now been committed as r51131.

Congrats on finally getting this into trunk!

Mitchell Stokes (moguri) closed this task as Resolved.Oct 7 2012, 2:10 AM