Lisp HUG Maillist Archive

Cannot set struct in Objective C

Hi,

I cannot set a struct for an SCNNode.position, where position is a struct of 3 floats. 
https://developer.apple.com/library/prerelease/ios/documentation/SceneKit/Reference/SCNNode_Class/index.html#//apple_ref/occ/instp/SCNNode/position and
https://developer.apple.com/library/prerelease/ios/documentation/SceneKit/Reference/SceneKit_DataTypes/index.html#//apple_ref/c/tdef/SCNVector3

I have defined an ObjC struct for SCNVector using define-objc-struct. As per the docs for invoke, http://www.lispworks.com/documentation/lw61/OBJC/html/objc-47.htm#46194, for 'other structures', 
-- The argument should be a foreign pointer to the appropriate struct object and is copied.

My understanding here is I just need to pass a pointer to SCNVector3. Is that right?

I am not able to identify why after I allocate a foreign object to SCNVector3, it ends up with this error:
-------

Error: #<Pointer to type (:STRUCT SCN-VECTOR3) = #x00112400> cannot be converted to foreign type (:STRUCT SCN-VECTOR3).
-------

I have attached the code in svn-position.lisp file. Just loading it will show the error. I am running LW 6.1 32 bit on OS X 10.10.

Thanks,
Deepak
-- 
http://deepaksurti.com
To see a miracle, be the miracle..

Re: Cannot set struct in Objective C

Eventually figured out the solution. The code to set the position is:

(fli:with-dynamic-foreign-objects ((new-pos scn-vector3))
  (setf
    (fli:foreign-slot-value new-pos 'x) 1.0
    (fli:foreign-slot-value new-pos 'y) 5.0
    (fli:foreign-slot-value new-pos 'z) 15.0)
  (format t "New position is ~A ~%" new-pos)
  ;(format t "Now error should occur .... ~%")
  (objc:invoke *sphere-node* "setPosition:"
               (fli:dereference new-pos :copy-foreign-object nil)))

Thanks,
Deepak

On Wed, Dec 3, 2014 at 6:03 PM, Deepak Surti <dmsurti@gmail.com> wrote:
Hi,

I cannot set a struct for an SCNNode.position, where position is a struct of 3 floats. 
https://developer.apple.com/library/prerelease/ios/documentation/SceneKit/Reference/SCNNode_Class/index.html#//apple_ref/occ/instp/SCNNode/position and
https://developer..apple.com/library/prerelease/ios/documentation/SceneKit/Reference/SceneKit_DataTypes/index.html#//apple_ref/c/tdef/SCNVector3

I have defined an ObjC struct for SCNVector using define-objc-struct. As per the docs for invoke, http://www.lispworks.com/documentation/lw61/OBJC/html/objc-47.htm#46194, for 'other structures', 
-- The argument should be a foreign pointer to the appropriate struct object and is copied.

My understanding here is I just need to pass a pointer to SCNVector3. Is that right?

I am not able to identify why after I allocate a foreign object to SCNVector3, it ends up with this error:
-------

Error: #<Pointer to type (:STRUCT SCN-VECTOR3) = #x00112400> cannot be converted to foreign type (:STRUCT SCN-VECTOR3).
-------

I have attached the code in svn-position.lisp file. Just loading it will show the error. I am running LW 6.1 32 bit on OS X 10.10.

Thanks,
Deepak
-- 
http://deepaksurti.com
To see a miracle, be the miracle.



--
http://deepaksurti.com
To see a miracle, be the miracle.
Updated at: 2020-12-10 08:33 UTC