//
// This is a patch for the Inventor 2.0 SoMFNode field, which can core
// dump when its values are deleted.
//
// To apply this patch, compile this file into a .o and then link
// the .o before -lInventor. The linker may give a warning.
// This is normal and expected.
//
#include
#include
#include
////////////////////////////////////////////////////////////////////////
//
// This overrides the definition in SO_MFIELD_ALLOC_SOURCE() to
// keep track of references and auditors.
//
////////////////////////////////////////////////////////////////////////
void
SoMFNode::allocValues(int newNum)
{
int i;
if (values == NULL) {
if (newNum > 0) {
values = new SoNode * [newNum];
// Make sure all pointers are initialized to NULL
for (i = 0; i < newNum; i++)
values[i] = NULL;
}
}
else {
SoNode **oldValues = values;
if (newNum > 0) {
values = new SoNode * [newNum];
for (i = 0; i < num && i < newNum; i++)
values[i] = oldValues[i];
// Initialize unused pointers to NULL
for (i = num; i < newNum; i++)
values[i] = NULL;
}
else
values = NULL;
// Free up any old stuff
if (oldValues != NULL) {
// Remove auditors and references on unused values
for (i = newNum; i < num; i++) {
if (oldValues[i] != NULL) {
oldValues[i]->removeAuditor(this, SoNotRec::FIELD);
oldValues[i]->unref();
}
}
delete [] oldValues;
}
}
num = maxNum = newNum;
}
http://www.sgi.com/tech/Inventor/workarounds/MFNode.C
(possibly inaccurate URL)
01/1995