## QPix v2.2 | ## Advanced topics

# Picture variables returned as command parameters

Many QPix commands get and return information in the same picture parameters. This technique modifies the original content of these parameters, in order to send the results to the caller. For example, the second parameter of QPx_GetImageFileThumbnail is a picture that will receive the thumbnail. In these commands use local picture variables.

The problem with process or interprocess variables is that 4D does not know if the variable has been modified by the plug-in. When the modified picture is displayed on a form (or perhaps manipulated in other ways), 4D can cause trouble to QuickDraw and the Memory Manager by crashing and probably damaging its internal structures. This problem is not private to QPix; all plug-ins access their parameters in the same way.

If you're not convinced you might want to try this simple crasher:

- Put on a form two process variables of type "picture", say gPicture and gCompressedPicture.
- Add a button with the following object method:

`gCompressedPicture:=gPicture` `$error:=QPx_CompressPicture(gCompressedPicture;"jpeg";512)`

- Load the gPicture variable with a picture and run the form in a dialog
- Click the button a few times
- Boom!

The problem can be avoided by using a local picture variable as the parameter that receives the compressed picture. The local picture can then be copied back to the process variable. Here is the fix:

`C_PICTURE($pict)` `$pict:=gPicture` `$error:=QPx_CompressPicture($pict;"jpeg";512)` `gCompressedPicture:=$pict`

Every now and then there are discussions in 4D-NUG about the dangers of using local variables for receiving data from plug-ins. What we are saying is that we have no evidence to affirm that such dangers exist. On the contrary, the above crasher snippet is a case where crashing is assured by using global variables, while everything is fine with local variables.

If you happen to experience otherwise unexplainable crashes with 4D (with or without QPix), you may consider using locals instead of globals to receive results returned by plug-ins.