Commits

Leonard Ritter committed 614ac06

fixed cast object being collected too early

Comments (0)

Files changed (1)

stbimage/__init__.py

     x = _ffi.new('int *')
     y = _ffi.new('int *')
     n = _ffi.new('int *')
-    result = _ffi.gc(_stbi_load(path,x,y,n,c), _stbi_image_free)
+    buffer = _stbi_load(path,x,y,n,c)
     x = x[0]
     y = y[0]
     n = n[0]
         size = x*y*c
     else:
         size = x*y*n
-    return x,y,n,_ffi.cast('unsigned char[{}]'.format(size), result)
+    buffer = _ffi.cast('unsigned char[{}]'.format(size), buffer)
+    result = _ffi.gc(buffer, _stbi_image_free)
+    return x,y,n,result
 
 # add wrapped functions
 _module_names = set(locals().keys())