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

Assertion failed: class_id < rt->class_count #8

Closed
Omnomios opened this issue Jan 30, 2020 · 0 comments
Closed

Assertion failed: class_id < rt->class_count #8

Omnomios opened this issue Jan 30, 2020 · 0 comments

Comments

@Omnomios
Copy link

If you call qjs::Context::registerClass after you have torn down and recreated a QuickJS instance it will assert with an error saying that the Class ID is too high.

This is happening because js_traits<std::shared_ptr<T>>::QJSClassId is a static member and does not get reset when the qjs::Context is destroyed.

I patched it to use a map in the context to keep track of the assigned IDs and if the map has been reset then reset the js_traits<std::shared_ptr<T>>::QJSClassId to zero.

Not sure of the best way to go about this but it was a workaround for me.

    template <class T>
    void registerClass(const char * name, JSValue proto = JS_NULL)
    {
        auto hashId = typeid(T).hash_code();
        if(this->classIds.count(hashId) == 0 && js_traits<std::shared_ptr<T>>::QJSClassId != 0)
        {
            js_traits<std::shared_ptr<T>>::QJSClassId = 0;
        }
        js_traits<std::shared_ptr<T>>::register_class(ctx, name, proto);
        this->classIds[hashId] = js_traits<std::shared_ptr<T>>::QJSClassId;
    }
@ftk ftk closed this as completed in 42a2a1b Jan 30, 2020
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

1 participant