Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

API->object->create(...) not calling default constructor #447

Open
AndrewAday opened this issue Jun 24, 2024 · 1 comment
Open

API->object->create(...) not calling default constructor #447

AndrewAday opened this issue Jun 24, 2024 · 1 comment
Assignees

Comments

@AndrewAday
Copy link
Contributor

For chugins, the API->object->create() method does not invoke the constructor of the type it creates.
E.g.

// Foo object that holds arbitrary data
struct Foo { char buff[256]; }

// default ck constructor of the object we're creating in a function
CK_DLL_CTOR(foo_ctor)
{
    // allocates memory to hold struct data
    OBJ_MEMBER_UINT(SELF, foo_data_ptr_offset) = (t_CKUINT) new Foo;   
}

// function that creates and returns a Foo
CK_DLL_SFUN(create_foo)
{
    Chuck_Object* foo_obj = API->object->create(SHRED, fooType, false);
    Foo* foo = (Foo*)OBJ_MEMBER_UINT(foo_obj, foo_data_ptr_offset);
    // ideally, `foo_ctor` has been called and memory has been allocated
    // but from my logging, foo_ctor is actually never called
    strcpy(foo->buff, "this will segfault");
    RETURN->v_obj = foo_obj;
}
@AndrewAday
Copy link
Contributor Author

In some cases the current behavior is beneficial actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants