ObjectMap's `find` method can get stuck in an infinite loop.
Part of my engine uses a Map to keep track of calls for a certain function.
var list: Array<Component>;
var firstUpdates: Map<Component, Bool>;
function ME_StartCheck(): Void {
for (comp in list) {
if (!comp.Enabled) continue;
if (firstUpdates[comp]) continue;
comp.OnStart();
firstUpdates[comp] = true;
}
}
After enough calls the find method gets caught in an infinite loop thanks to ckey starting as zero and _MNEXT(m,c) also returning zero.
_MSTATIC _MVAL_TYPE *_MNAME(find)( t_map *m, t_key key ) {
int c, ckey;
unsigned int hash;
if( !m->values ) return NULL;
hash = _MNAME(hash)(key);
ckey = hash % ((unsigned)m->ncells);
c = _MINDEX(m,ckey);
while( c >= 0 ) {
if( _MMATCH(c) )
return &m->values[c].value;
c = _MNEXT(m,c);
}
return NULL;
}
I'm not familiar enough with HashLink to come to a conclusion on how this happens. But the objects I store in the map are never iterated over or constantly changing. The map also isn't created in C, it is only interacted with via Haxe code.
We would need a reproducible sample.
Le mar. 21 janv. 2025, 22:15, .RYEN @.***> a écrit :
Part of my engine uses a Map to keep track of calls for a certain function.
var list: Array<Component>;var firstUpdates: Map<Component, Bool>; function ME_StartCheck(): Void { for (comp in list) { if (!comp.Enabled) continue; if (firstUpdates[comp]) continue; comp.OnStart(); firstUpdates[comp] = true; } }
After enough calls the find method gets caught in an infinite loop thanks to ckey starting as zero and _MNEXT(m,c) also returning zero.
_MSTATIC _MVAL_TYPE *_MNAME(find)( t_map *m, t_key key ) { int c, ckey; unsigned int hash;
if( !m->values ) return NULL; hash = _MNAME(hash)(key); ckey = hash % ((unsigned)m->ncells); c = _MINDEX(m,ckey); while( c >= 0 ) { if( _MMATCH(c) ) return &m->values[c].value; c = _MNEXT(m,c); } return NULL; }
I'm not familiar enough with HashLink to come to a conclusion on how this happens. But the objects I store in the map are never iterated over or constantly changing. The map also isn't created in C, it is only interacted with via Haxe code.
— Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/hashlink/issues/745, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHZXQAUTI4IMJYXMUDIJ5L2L22GRAVCNFSM6AAAAABVTOD66KVHI2DSMVQWIX3LMV43ASLTON2WKOZSHAYDEOBSGYYTKNI . You are receiving this because you are subscribed to this thread.Message ID: @.***>