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

[Documentation] Custom cpcalloc actually does need to zero memory #250

Open
nbr0wn opened this issue Jun 30, 2024 · 0 comments
Open

[Documentation] Custom cpcalloc actually does need to zero memory #250

nbr0wn opened this issue Jun 30, 2024 · 0 comments

Comments

@nbr0wn
Copy link

nbr0wn commented Jun 30, 2024

In "Memory management the Chipmunk Way", there is a section which reads:

cpSpaceAlloc() – Allocates but does not initialize a cpSpace struct. All allocation functions look more or less like this: return (cpSpace *)cpcalloc(1, sizeof(cpSpace)); You can write your own allocation functions if you want. It is not a requirement that the memory be zeroed.

..turns out if you don't zero the memory, you can fail on an assert in cSpatialIndexInit() - cSpacialIndex.c line 41:

cpAssertHard(!staticIndex->dynamicIndex, "This static index is already associated with a dynamic index.");

... because the dynamicIndex pointer contains whatever garbage was in memory at alloc time.

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