Unable to promote to my C++ subclass type

I’ve followed the code in https://github.com/mcneel/rhino-developer-samples/blob/6/cpp/SampleMarker/SampleMarkerEventWatcher.cpp for pasting of custom objects.

I’ve gotten as far as the vtable pointer comparison (marked with a comment below), but the comparison fails and the object type change never occurs. I’ve checked and double checked this and don’t see an obvious reason why it fails. I’m so close here…

Btw… manually manipulating vtables is extremely ugly and likely not portable… Is there a more sane way to do this in production code?

class SuperDEventWatcher : public CRhinoEventWatcher
{
public:
  CCommandSuperD2 *owner;

  SuperDEventWatcher(CCommandSuperD2 *owner) : owner(owner)
  {
  }

  static void promoteRhinoMeshObjectToSuperDObject(const CRhinoMeshObject *meshObj)
  {
    static void *CSuperDMeshObject__vtable_ptr = 0;
    static void *CRhinoMeshObject__vtable_ptr = 0;

    if(!meshObj)
      return;

    if(!CSuperDMeshObject__vtable_ptr)
    {
      CRhinoSuperDMeshObject a;
      CSuperDMeshObject__vtable_ptr = ON_ClassVtable((void *)(&a));
      CRhinoMeshObject b;
      CRhinoMeshObject__vtable_ptr = ON_ClassVtable((void *)(&b));
    }

    //HERE:  This if statement is always false **********
    if(CRhinoMeshObject__vtable_ptr == *((void **)meshObj))
    {
      // Change from CRhinoMeshObject vtable to CSuperDMeshObject__vtable_ptr vtable
      *((void**)meshObj) = CSuperDMeshObject__vtable_ptr;
    }
  }

  void OnEndOpenDocument(CRhinoDoc &doc, const wchar_t *filename, BOOL bMerge, BOOL bReference) override
  {
    UNREFERENCED_PARAMETER(filename);
    UNREFERENCED_PARAMETER(bMerge);
    UNREFERENCED_PARAMETER(bReference);

    CRhinoObjectIterator it(doc, CRhinoObjectIterator::undeleted_objects, CRhinoObjectIterator::active_objects);
    it.SetObjectFilter(ON::mesh_object);

    const CRhinoObject *obj = 0;
    for(obj = it.First(); obj; obj = it.Next())
    {
      const CRhinoMeshObject *meshObj = CRhinoMeshObject::Cast(obj);
      if(meshObj && CSuperDUserData::HasSuperDUserData(meshObj))
      {
        promoteRhinoMeshObjectToSuperDObject(meshObj);
      }
    }
  }
};

Looking deeper, I’m sure this has something to do with the fact that I attach to attributes and not geometry user data.

bool rc = const_cast<CRhinoObject *>(object)->AttachAttributeUserData(pUserData);

I see zero of my object constructors being called and I just end up with a plain mesh that has no attributes user data upon paste. How can I get copy/paste to work with attributes user data? (I can’t use geometry attached data since I change the geometry multiple times).

This may be the thing that beats me… after multiple days trying to get copy paste going… I’m losing the will to go on here…

The exciting conclusion: my CSuperDUserData::Read method was silently failing and returning false, resulting in the lack of attached data.

It works now.