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

Template class double registration #12

Open
ghost opened this issue May 11, 2022 · 1 comment
Open

Template class double registration #12

ghost opened this issue May 11, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented May 11, 2022

Here is the situation. I have an Engine library (DLL) where I try to reflect the std::vector class.
I wanted to use this reflected vector in a Scripting dll driven by an Editor application. (Manipulate and display the vector content in an inspector).
The problem is that when I'm trying to declare one in the Scripting dll, double registration warnings show up.

[Refureku] WARNING: Double registration detected: (6467467976038935076, HyVector) collides with entity: (6467467976038935076, HyVector)
[Refureku] WARNING: Double registration detected: (2076874076076324754, GetElementAt) collides with entity: (2076874076076324754, GetElementAt)
[Refureku] WARNING: Double registration detected: (7605404597672029496, size) collides with entity: (7605404597672029496, size)
[Refureku] WARNING: Double registration detected: (9954276657655150362, AddNewElement) collides with entity: (9954276657655150362, AddNewElement)

Here is the vector class :

// STDTemplateClass used as a global instance for all standard template classes
template <typename Type>
class HY_CLASS() HyVector final : public STDTemplateClass, public std::vector<Type>
{

public:
	HY_METHOD() std::size_t size();
	HY_METHOD() void* GetElementAt(std::size_t index);
	HY_METHOD() void* AddNewElement();

	HyVector_GENERATED
};

This drives to another problem. When I'm trying to retrieve some methods from the class template instantiation given by the field archetype, methods are not found and are set to null. I bypassed this problem by retrieving the base archetype on the database from the field archetype ID.

// From field archetype
rfk::Archetype const* fieldArchetype = field.getType().getArchetype();
rfk::ClassTemplateInstantiation const* cTempInstance = rfk::classTemplateInstantiationCast(fieldArchetype );

// Retrieve vector instance
STDTemplateClass& vecClass = *reinterpret_cast<STDTemplateClass*>(field.getPtr(owner));

// Here, the getMethod is not valid
rfk::Method const* getMethod = cTempInstance->getMethodByName("GetElementAt");


// From field archetype ID
fieldArchetype = rfk::getDatabase().getClassById(fieldArchetype ->getId());
cTempInstance = rfk::classTemplateInstantiationCast(fieldArchetype);

// Here, the getMethod is valid and usable
getMethod = cTempInstance->getMethodByName("GetElementAt");
@jsoysouvanh jsoysouvanh added the bug Something isn't working label May 11, 2022
@jsoysouvanh jsoysouvanh self-assigned this May 11, 2022
@jsoysouvanh
Copy link
Owner

Hi, thank you for your feedback.

I indeed forgot to consider the case the same template is used in different translations units leading at a duplication of the same archetype...
It doesn't seem trivial to fix either, I'll need a bit of time to find an elegant solution to fix this problem. Off the top of my head, I don't understand why the archetype duplicate doesn't contain the reflected method neither.

The workaround is almost performance-free so I recommand people having this issue to use it until the bug is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant