fanhe wrote:Is there a way to copy a space safely?
Depends what you mean by copy. If you want to keep states of all spaces and switch between these states in memory in the current process (i.e. no write/load to disk between processes), then it isn't hard to already do this. All you need is to create custom allocator functions and define cpcalloc, cpfree etc to your functions. Then keep a global memory arena which your allocator uses, which is large enough to hold your spaces. When you want to save your spaces, just memcpy your arena to some other block of memory, and when you want to restore your space just memcpy it back.
I tried to do this with Casey Muratori's looped live reloading, but unfortunately chipmunk litters function pointer in with its data, so once the dll is reloaded the function pointers inside the memory arena are often no longer correct. I'm not sure how to fix this problem. Perhaps resetting the function pointers after the dll is loaded will work, but I will need to patch chipmunk to expose these functions so that the pointers can be reset.