[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (rlet ((m (:pointer (:pointer :movierecord))))...)

>I have two questions.
>I wrote a simple MCL code to play movies.
>_NEWMOVIEFROMFILE requires :pointer to :pointer to :movierecord as
>it's first argument.
>  (resrefnum :SIGNED-INTEGER) (resid (:POINTER :SIGNED-INTEGER)) 
>  (resname (:STRING 255)) (newmovieflags :SIGNED-INTEGER) 
>  (datarefwaschanged (:POINTER :BOOLEAN))
>  [trap ]
>  Returns:  :SIGNED-INTEGER
>rlet seems to accept such expression as follow, but it is not
>documented in MCL2.0 Reference. 
>(rlet ((m (:pointer (:pointer :movierecord)))...)
>  ...
>  (setq err (#_NewMovieFromFile
>             m
>             resrefnum
>             resID
>             (%null-ptr)
>             #$newMovieActive
>             was-changed))
>  ...
>  (setq movie (%get-ptr m))
>  ...
>  )
>My code is working now, but is this right or not recommended? 
>And where the :movierecord allocated? On the stack or else somewhere?
>Should I (#_disposemovie movie)?

What you're getting from:

(rlet ((m (:pointer (:pointer :movierecord)))...) ...)

is 4 bytes allocated on the stack which contain random bits.
I do not have QuickTime documentation handy, so I can only guess what
the #_NewMovieFromFile trap does. Seems to me that it will be one of
the following:

1) It creates a handle and stores it in the 4 bytes that your RLET
   allocated on the stack. In this case, your code will need to
   (#_DisposeMovie m) in order to prevent a memory leak.

2) It assumes that m is a handle to a movierecord. In this case,
   it will write into random memory causing your program or another
   application to crash mysteriously at some future time.
   In this case, what you really need to do is:

(let ((m (make-record :movierecord :storage :handle)))
  (declare (dynamic-extent m))
    (do-something m)
    (#_DisposeMovie m)))

>I used ccl::gestalt (It is not documented too) to determine whether
>the movie toolbox is installed.
>  (if (/= 0 (ccl::gestalt #$gestaltQuickTime))
>      (#_EnterMovies)
>      #$movieToolboxUnitialized)
>Is this right or not recommended?

I can't officially sanction the use of non-exported functions, but your
use of ccl::gestalt is correct and I doubt that we're going to remove
it any time soon.