WopsS / RED4ext.SDK

A library to create mods for REDengine 4 (Cyberpunk 2077), independently of RED4ext.
MIT License
93 stars 31 forks source link

Adds iterator to HashMap #62

Closed jackhumbert closed 5 months ago

WopsS commented 1 year ago

Looking at HashMap::ForEach I don't really understand how it works, don't we need a custom iterator?

jackhumbert commented 1 year ago

I'm not sure, but it complained about this for loop until I added these, which mirror DynArray's.

WopsS commented 1 year ago

DynArray is a contiguously memory, but this one has buckets / nodes. So I am a bit confused.

If I am right the following:

auto rttiSystem = RED4ext::CRTTISystem::Get();
for (auto node : rttiSystem ->types)
{
    // ...
}

will be translated to after compilation:

auto rttiSystem = RED4ext::CRTTISystem::Get();
auto begin = rttiSystem->begin();
auto end= rttiSystem->end();

while (begin != end)
{
    // ...
    being += sizeof(HashMap::Node);
}

Which is wrong.

I think we are running in an undefined behavior in a long run.