I'm writing the jit.openni external using your Max SDK. I am having difficulty with the jit linked list module.
If I call jit_linklist_insertindex(pLinkedList, pObject,0L) on an empty linked list, the insert fails and Max crashes. This is not the behavior I would expect. ;-) Since I gave it the head (0L), I would expect it to insert one node in the list.
My intention is to have storage for registering/unregistering callbacks in jit.openni. Rather than a fixed size callback function array, I think a linked list is more flexible. The data I want to store in the linked list is the callback function pointer.
Is there an oversight in my code or your sdk leading to this crash? I am able to use jit_linklist_append() and then right after it use jit_linklist_objptr2index() to get the index of what I stored. And then use the undocumented jit_linklist_index2ptr() to get the pointer. I prefer the pointer because the index is not guaranteed to change spontaneously through sorting, insert by another thread, etc. Seems messy.
There are some nice undocumented functions I can see in jit.linklist.h but unfortunately some of the good ones (that I would use) are not exported.
A 2nd question. I am storing a pointer to a callback function, not a pointer to a t_jit_object. When time to rid myself of a linked list node when unregistering the callback, I am using jit_linklist_chuckindex() because ...delete() appear to try to free the object of the pointer. Is this approach ok? And since I am using ...chuck(), is chuck() freeing the linked link node structure itself or is that a memory leak occurring.
Here's my code paraphrased:
t_jit_err RegisterJitOpenNIEventCallbacks(t_jit_openni *x, JitOpenNIEventHandler funcCallback, long *pUnregister) =====================================================
void *arbitraryPointer; // note that this doesn't necessarily point to a t_jit_object, in my case its the pointer to the callback function
x->pEventCallbackFunctions = (t_jit_linklist *)jit_object_new(_jit_sym_jit_linklist);
if ((*pUnregister = jit_linklist_insertindex(x->pEventCallbackFunctions, funcCallback, 0L)) == -1)
t_jit_err UnregisterJitOpenNIEventCallbacks(t_jit_openni *x, long lUnregister) =============================================
if (jit_linklist_chuckindex(x->pEventCallbackFunctions, lUnregister) == -1) // I'm using chuck instead of delete since the pointer stored isn't a t_jit_object
LOG_DEBUG("linklist_delete returned an error");