Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

class.hpp: C++ objects referenced with reference_external are still deleted when class_::destroy() is called #60

Closed
scottd72 opened this issue Jun 26, 2017 · 1 comment

Comments

@scottd72
Copy link

Calling class_::reference_external "does not take ownership of the C++ pointer", but v8pp still deletes the C++ object when class_::destroy is called, which is clearly not intended and leads to crashes due to double deletion.

The "destroy_after" parameter of class_singleton::wrap is only used to determine what callback is given to SetWeak, and isn't stored anywhere in the actual object registry, and so v8pp isn't actually keeping the necessary ownership information everywhere it needs to.

This affects both the shared_ptr branch and the main branch.

pmed added a commit that referenced this issue Jul 24, 2017
Mark persistent handles for externally referenced objects as independent,
and do not call `destroy` function for such objects
@pmed
Copy link
Owner

pmed commented Jul 28, 2017

Hi @scottd72

I've fixed this issue by marking persistent handles for externally referenced objects as independent,
and do not call destroy function for such objects.

@pmed pmed closed this as completed Jul 28, 2017
pmed added a commit that referenced this issue Feb 4, 2018
`MarkIndependent()` in persistent handle class has been deprecated since recent
V8 versions (ca. >= 6.0), so `IsIndependent()` returns always true.
This deprecation breaks the mechanism of marking externally referecned wrapped
C++ object those shall not be deleted.

To fix it, an additional internal `v8::Object` field has been added
(total fields count becomes 3) to store a pointer to a wrapped object
destructor function. Such an internal pointer field must be aligned by 2, but
unfortunately, Visual C++ can generates an unaligned pointer to destroy function.

At the current time the single destructor function per wrapped class is stored
in the `object_registry`, so thar 3rd internal fields in a wrapped object is
used as a simple marker wether to call the object destructor or not.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants