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

Memory management? #40

Closed
snells opened this issue Sep 14, 2015 · 2 comments
Closed

Memory management? #40

snells opened this issue Sep 14, 2015 · 2 comments

Comments

@snells
Copy link

snells commented Sep 14, 2015

I was trying to render 16 * 16 * 16 boxes.
I collected the vertices into one list and indices into other, so all of the vertices from 4096 boxes where in the same list.

(let ((vr (make-gpu-array verts :dimensions v-count :element-type 'g-pnc))
      (ir (make-gpu-array ind :dimensions i-count :element-type :unsigned-int)))
    (vector-push-extend (cons id (make-buffer-stream vr :index-array ir)) meshes)
    (free-gpu-array vr)
    (free-gpu-array ir)

Then I rendered, and it worked. I called free-vertex-stream on the buffer-stream.
I tried to create new mesh but I got opengl error 1285 . out-of-memory

Is it correct to free the gpu arrays after the stream has been made?
What am I not freeing correctly if I run out of memory?

I was looking at cepl's source and found possible bug?
delete-vertex-arrays is not inside the loop.

(defun free-vaos (vaos)
  (with-foreign-object (id :uint (length vaos))
    (loop :for vao :in vaos :for i :from 0 :do
      (setf (mem-aref id :uint i) vao))
    (%gl:delete-vertex-arrays 1 id)))
@cbaggers
Copy link
Owner

Great catch, thankyou, i'll fix this asap.
Sorry for how long it's been since I last made changes to cepl. I'll have a video out soon explaining what I've been up to.

@cbaggers
Copy link
Owner

cbaggers commented Jul 16, 2016

This was a bug but not the one we thought. #'delete-vertex-arrays takes a ptr to a foreign array of uints and deletes all of them at once. The problem is that I was telling it only to delete one of the ids from the array.

(%gl:delete-vertex-arrays 1 ids)
;;                       ^^^ the mistake

Also you musn't delete the gpu-arrays if you have a stream using them as the stream streams the data from the gpu-arrays.

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

2 participants