#How to use AutoHashMap? I keep getting segfaults with it.

1 messages · Page 1 of 1 (latest)

wild hedge
#

Hi, I must be doing something wrong, but I've tried a lot of various ways, and I can't figure out how to use the AutoHashMap.

Using the iterator methods always segfaults with this (full stack trace in the Gist link),

var it = state.SDLEventToAction.keyIterator();
while (it.next()) |known_key| {
    Log.debug("Key ID {} found!\n", .{known_key});
}

Here's the full code, https://gist.github.com/jrasanen/aed02ceff46dbc787bf90a713176ea9b#file-main-zig-L109

Zig version: 0.11.0-dev.3964+3d5751b57, also tried 0.11.0-dev.3946.

Thanks!

primal grove
#

the problem is that the hash map itself is pointing to data on the fixed buffer allocator, but when the function ends, the allocator goes out of scope, and it is pointing to data that is overwritten on the stack

#

instead of a fixed buffer allocator, you should probably use a general purpose allocator

ionic blade
#

or a c_allocator if u want speed

#

gpa is rly slow

primal grove
#

yeah

#

but gpa will find leaks, which is very nice

ionic blade
#

i like setting gpa in debug mode

wild hedge
#

Ahh, of course, thanks. What kinda confused me is that I was able to run count() etc for it

primal grove
#

yeah, because it's in the stack, the memory might not be fully overwritten yet

wild hedge
#

Yes, my bad, thanks for helping

primal grove
#

zig should probably have some safety checks for that in the future

#

no probnlem @wild hedge

wild hedge
#

Yea, now it's obvious but perhaps some guards against that, or an error message regarding could be nice.