QHYCCD

Possible Memory Leak in qhyccd.dll

Possible Memory Leak in qhyccd.dll
« on: May 19, 2020, 03:33:17 PM »
I am a LabVIEW programmer and I have been writing a program to support my QHY294C.  I can control the camera but when I go to exit my program generates a crash report.  I have contacted LabVIEW support people and they can't figure out why the crash is happening.  They say that LabVIEW works with lots of 3rd party dlls without issue.

I was able to create a very simple LabVIEW demo program that first executes InitQHYCCDResource() and then executes ReleaseQHYCCDResource().  There are no other calls to the dll in this demo program.  There are no errors generated by these functions but the program crashes when it exits.  It's as if not all of the resources are being released or that something that InitQHYCCDResource() does that is not being un-done.  I know that there are many programs written using this dll that don't have this problem but I need some guidance as to what this issue could be.

Please advise

Peter
« Last Edit: May 19, 2020, 03:34:50 PM by pmwolsley »

Re: Possible Memory Leak in qhyccd.dll
« Reply #1 on: May 19, 2020, 08:16:57 PM »
Hi,
    Which version SDK do you use?
Best Regards,
QinXiaoXu

Re: Possible Memory Leak in qhyccd.dll
« Reply #2 on: May 25, 2020, 01:40:47 PM »
The GetQHYCCDSDKVersion functions returns 2020/2/28 as the version date of qhyccd.dll

Peter

Re: Possible Memory Leak in qhyccd.dll
« Reply #3 on: May 25, 2020, 08:03:31 PM »
    Well,we released a new version SDK,maybe you can try it.https://www.qhyccd.com/html/prepub/log_en.html#!log_en.md
Best Regards,
QinXiaoXu

Re: Possible Memory Leak in qhyccd.dll
« Reply #4 on: May 26, 2020, 11:22:28 AM »
I just finished testing with the 2020.05.22 qhyccd.dll
The simple DEMO program no longer crashes

My full program simultaneously uses a QHY294C and a QHY5II-M.  The QHY294C is detected first and functions properly.  When I run the routine which uses the QHY5II-M it recognizes the camera but will not perform a Live-frame stream.  If I stop my program it will no longer crash.  If I edit the program to only run the QHY5II-M routine it will see the camera and perform the Live-frame stream.

It seems as if this version of the DLL will not allow me to access my two cameras at the same time.  The older version of the DLL had no problem accessing both cameras.

Peter

Re: Possible Memory Leak in qhyccd.dll
« Reply #5 on: May 26, 2020, 11:37:27 AM »
I also just did a quick test using qhyccd.dll version 2020.05.08

When I run my DEMO program it crashes.  So only version 2020.05.22 does not crash.  Unfortunately v2020.05.22 does not allow me to use my QHY294C and QHY5II-M at the same time.

Peter

Re: Possible Memory Leak in qhyccd.dll
« Reply #6 on: May 26, 2020, 08:39:08 PM »
Hi,
    I inquired my colleague about this function,he told me,this SDK can support two cameras work on Live Mode at same time.Could you send the order list of executing SDK API to me?I will do same test.
Best Regards,
QinXiaoXu

Re: Possible Memory Leak in qhyccd.dll
« Reply #7 on: May 27, 2020, 11:24:45 AM »
I will get back to you later today with a full list of the SDK calls being used.  I have my QHY294C configured for Single-frame stream.  When I try to run my QHY5II-M configured for Live stream I can initially connect to the camera but it doesn't seem to be able to establish a Live stream.

Re: Possible Memory Leak in qhyccd.dll
« Reply #8 on: May 27, 2020, 03:02:16 PM »
My program for using my QHY5II-M in Live stream mode has been programmed using your SDK guide.  It has been working for me quite well.  Today I did some more testing.
Using qhyccd.dll v20.5.24 32bit
I connect and disconnect my QHY294C via the SDK software commands.
-If I have the QHY294C connected for Single Frame mode I cannot connect my QHY5II-M for Live frame mode.
-If I disconnect my QHY294C I can connect my QHY5II-M for Live frame without issue.
-If I disconnect the QHY5II-M and then re-connect the QHY249C in Single frame mode I cannot connect the QHY5II-M in Live frame mode.

-If I connect my QHY294C in SIngle-frame mode and then run PHD2 and connect it to my QHY5II-M this creates a situation where both cameras are running in single frame mode.  PHD2 is very sluggish in displaying updated frames.  PHD2 will display 4 or 5 frames at the correct rate (1 second) and then it will not update for 3 or 4 seconds.  Then it will display 4 or 5 frames at the correct rate and stop updating again.  So PHD2 is being affected by this issue.  I am using the latest version of PHD2 which is using qhyccd.dll v18.5.2.0

If I go back to using qhyccd.dll v20.2.28 my program runs smoothly and PHD2 is able to update it's screen...even at 0.1s updates...but my program crashes when I ask it to exit.  When I use v20.5.24 my program does not crash when exiting.
« Last Edit: May 27, 2020, 03:05:28 PM by pmwolsley »

Re: Possible Memory Leak in qhyccd.dll
« Reply #9 on: May 27, 2020, 08:11:03 PM »
    Ok,after I get your list,I will do test.And you connect QHY294C and QHY5IIM is not always at the same time?But connect one camera,after that connect another one?
Best Regards,
QinXiaoXu

Re: Possible Memory Leak in qhyccd.dll
« Reply #10 on: May 28, 2020, 02:24:59 PM »
Here are the SDK calls for my QHY294C. Most of these calls occur when the program starts.  I then have a sequencer that will make calls to the TakePicture: code as required.  I program in LabVIEW so I have created a pseudo code style for showing the steps taken.  QHY294Request is set to TRUE when the program starts.

InitQHYCCDResource  ;I have made sure that this call happens only once in my program
Loop:
If QHY294CRequest=FALSE GOTO Loop:  loop until QHY294CRequest is TRUE;
Loop1:  ;loop here until QHY294C is detected
ScanQHYCCD
Test ALL detected cameras
GetQHYCCDId
Is QHY294C available
If NOT available GOTO Loop1:

QHY294C has been detected so get initial values
OpenQHYCCD(QHY294C camera Id)
GetQHYCCDVersion  ;for display purposes
GetQHYCCDChip
SetQHYCCDStream(Single)  ;Single frame is default can change this as needed
InitQHYCCD
GetQHYCCDEffective
IsQHYCCDControlAvailable(CAM_COLOR)  ;decode Bayer matrix
GetQHYCCDMem

Get parameter list to display for user interface
For i=0 to 25
GetQHYCCDParam(i)
IsQHYCCDControlAvailable(i)
GetQHYCCDParamMinMaxStep(i)
Populate table for parameters (current value, min/max limit and if ControlAvailable)
Next i

InitializeSingleFrameMode:
If StreamMode = Live  then StopQHYCCDLive  ; If switching from Live to Single then StopQHYCCDLive
CloseQHYCCD
ReleaseQHYCCDResource
ScanQHYCCD
OpenQHYCCD(QHY294C camera Id)
SetQHYCCDStream(Single)
InitQHYCCD
SetQHYCCDBits  ;16 bit mode
SetQHYCCDBin   ;1x1 binning
SetQHYCCDDebayer  ;false
SetQHYCCDResolution ;Full chip size 4212x2850
SetQHYCCDResolution  ;Effective area 36,28,4164,2796

Note:All of the SDK calls listed so far are executed every time that the program starts. Some of the code are subroutines that can also be called when switching from Single to Live or when switching from Live to Single

The following code is executed when the sequencer requests a photo be taken.  The sequencer also sets GAIN,EXPOSURE etc. as requested by the user.

TakePicture:
ExpQHYCCDSingle
Loop2:  loop here until exposure complete
GetQHYCCDExposure
If Exposure > 0  GOTO Loop2
GetQHYCCDSingleFrame ;
Save Exposure to Disk

If ever I decide to disconnect the QHY294C the follow code is used...

If QHY294CRequest=FALSE CloseQHYCCD
GOTO Loop:

Upon Program Exit
ReleaseQHYCCDResource
« Last Edit: May 28, 2020, 02:54:45 PM by pmwolsley »

Re: Possible Memory Leak in qhyccd.dll
« Reply #11 on: May 28, 2020, 02:52:15 PM »
Logic for Connecting and Live streaming QHY5II-M.  This routine is always run after the QHY294C has been connected.  This routine displays the QHY5II-M image to the user and also overlays some graphics on the image.  The user will typically use the routine for 5 or 10 minutes and then exit this routine. QHY5II-MRequest is always TRUE when this routine is run.

Loop:
QHY5II-MRequest=FALSE GOTO Loop:  loop until QHY5II-MRequest is TRUE;
Loop1:  ;loop here until QHY5II-M is detected
ScanQHYCCD
Test ALL detected cameras
GetQHYCCDId
Is QHY5II-M available
If NOT available GOTO Loop1:

QHY5II-M Is available
OpenQHYCCD
SetQHYCCDStream(Live)
InitQHYCCD
SetQHYCCDBits ;8 bit mode
SetQHYCCDParam(USBTraffic)  ;set to 0
SetQHYCCDBin  ;1x1 binning
SetQHYCCDResolution  ;1280x1024
GetQHYCCDParamMinMaxStep (CONTROL_GAIN) ;used to limit available gain adjustment
SetQHYCCDParam  ;Set the camera GAIN
SetQHYCCDParam  ;Set the camera Exposure
BeginQHYCCDLive
GetQHYCCDMem

Loop2:
GetQHYCCDLive
If ret = -1 then GOTO Loop2:
Process Live Frame as needed

If QHY5II-MRequest = TRUE then GOTO Loop2:  ;loop if camera is still needed
CloseQHYCCD
Exit routine
« Last Edit: May 28, 2020, 02:58:47 PM by pmwolsley »

Re: Possible Memory Leak in qhyccd.dll
« Reply #12 on: May 28, 2020, 08:12:54 PM »
Hi,
    About InitQHYCCD() function,please just call one time.This is a initialize function,second call will make initialize your setting.
Best Regards,
QinXiaoXu

Re: Possible Memory Leak in qhyccd.dll
« Reply #13 on: May 29, 2020, 11:06:26 AM »
Thank-you for reviewing my SDK usage.  I agree that the InitQHYCCD will reset any existing settings.  In the SDK list for using the QHY294C the first InitQHYCCD is to allow my program to extract chip details (width, height, Bayer matrix etc., effective area, image memory allocation)  All of these values are constants for the QHY294C so they are gathered at start-up. I believe I need to use InitQHYCCD here in order to access these values.

I have MACRO functions defined in my program [GetParameterList, InitializeLiveStream and InitializeSingleStream]  These allow me to switch modes easily.  The GetParameterList MACRO is shown in my SDK list.  Based upon your comment I should wait to use the GetParameterList MACRO until I have executed either the InitializeLiveStream or InitializeSingleStream MACROs because both of these MACROs use the InitQHYCCD.

Best Regards,

Peter

Re: Possible Memory Leak in qhyccd.dll
« Reply #14 on: May 31, 2020, 08:37:29 PM »
    OK,just try it.And I attached a manual of SDK in you another topic,you can check if it is helpful for you.
Best Regards,
QinXiaoXu