billyquith / ponder

C++ reflection library with Lua binding, and JSON and XML serialisation.
http://billyquith.github.io/ponder/
Other
645 stars 95 forks source link

Destroy object causes a runtime failure #125

Open ksuryagiridhar opened 3 years ago

ksuryagiridhar commented 3 years ago

Hi,

I am trying to use ponder for reflection. I create instances of a class declared to ponder and then store the pointer to the objects in a generic datamodel.

The code looks something like below:

bool object_factory()
{  
  const ponder::Class& metaClass = ponder::ClassByType<Type>();
  ponder::UserObject object = ponder::runtime::create(metaClass);
  void* ptr = object.pointer();
  if(add_to_datamodel(ptr) == FAILURE)
  {
    ponder::runtime::destroy(object);
    return FAILURE;
  }
  return SUCCESS;
}

The code builds fine and I see below runtime error when I execute unit test where the add_to_datamodel failed. The object destroy is leading to an invalid pointer.

free(): invalid pointer
Aborted

I run google tests on ubuntu 20.04 version.

I tried to maintain object creation and destruction similar to the library examples and it doesn't work, could you help me with the issue?