;; This seems to solve the problem above ;; callback used by our C-function. It returns itself, thus, the ;; result of C_callback is the callback function itself - ;; this is useful because sometimes this callback-function ;; is moved by the GC! So the original callback would point ;; to the old location and be invalid. (define (callback-wrapper proc) (let* ([self #f] [cbwrap (lambda (cp-pointer) ; coming from C-land (proc cp-pointer) self)]) (set! self cbwrap) cbwrap)) (define (cp:for-each/shape space callback) ((foreign-safe-lambda void "forEachShape" (c-pointer "cpSpace") scheme-object) space (callback-wrapper callback)))