EPICS Home

Experimental Physics and Industrial Control System


 
1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: Custom file saving plugin in AreaDetector
From: Mark Rivers <[email protected]>
To: "'Hinko Kocevar'" <[email protected]>, EPICS tech-talk <[email protected]>
Date: Thu, 18 Jul 2013 22:08:06 +0000
Hi Hinko,

Thanks for pointing out this problem, I had not encountered it before.  But it was definitely a bug.

I have fixed the problem several ways.  First I added a check that this->pCapture is NULL, and print an error message if it is.  This prevents the crash.

But I also changed the way the capture buffer is freed.  Previously it was freed whenever WriteFile was processed.  This is no longer the case, it is only freed when a new capture is begun.  This means that the user can now click "Save" repeatedly during a capture, and a larger and larger file will be written (assuming the file format supports multiple images per file).  When capture is done the user can still press Save multiple times, saving to a different file name, etc.  Only when a new capture is started is the memory buffer cleared.  This is less efficient in terms of memory use, but it has more functionality and is more user-friendly.

You can get the new version at

https://subversion.xor.aps.anl.gov/synApps/areaDetector/trunk

if you would like to test it, and I would be happy if you did.

Thanks,
Mark


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hinko Kocevar
Sent: Thursday, July 18, 2013 5:48 AM
To: EPICS tech-talk
Subject: Custom file saving plugin in AreaDetector

Hi,

Segmentation fault happens when saving data to a file from my custom 
made file saving plugin, that extends the NDPluginFile base class like 
all other file saving plugins.
Saving mode is Capture, meaning a capture buffer, of user specified 
capture size, is preallocated in advance. During capturing, NDArrays are 
put into this buffer through callbacks. Actual file saving can occur 
either when the number of captures(captured NDArrays) reaches the number 
specified by the user, or when the user manually clicks save before the 
actually capturing has finished. When saving is done, the preallocated 
capture buffer is freed. If capturing is still carried on after the 
saving, which does happen in the case of user clicking save prematurely 
before the capturing reaches the number specified by the user, 
segmentation fault happens.
The segmentation fault happens in code NDPluginFile.cpp at line 594 
(EPICS base 3.14.12.3):

591 case NDFileModeCapture:
592 if (capture) {
593 if (numCaptured < numCapture) {
594 this->pNDArrayPool->copy(pArray, this->pCapture[numCaptured++], 1);
595 arrayCounter++;
596 setIntegerParam(NDFileNumCaptured, numCaptured);

Inspecting the segmentation fault, pCapture was a NULL pointer, the 
numCaptured was the size of captured NDArrayes at clicking save prematurely.

Since the capture buffer is freed after save, I will avoid this problem 
by stopping the capture when save is done.

Is a better way to handle this? Maybe there should be a check in the 
code to avoid segmentation fault, when the NDArray buffer is NULL.

Best regards,
Hinko


-- 
Hinko Kocevar
Software development engineer
Instrumentation Technologies d.d.
Velika pot 22, SI-5250 Solkan - Slovenia
T:+386 5 3352600, F:+386 5 3352601
E-mail: [email protected]
http://www.i-tech.si

The information transmitted is intended solely for the
addressee and may contain confidential and/or privileged
information. Any review, retention, disclosure or other use
by persons other than the intended recipient is prohibited.
If you received this in error, please notify the sender and
delete all copies.



Replies:
Re: Custom file saving plugin in AreaDetector Hinko Kočevar
References:
Custom file saving plugin in AreaDetector Hinko Kočevar

Navigate by Date:
Prev: Re: motor record & PC6K: program upload fails Pearson, Matthew R.
Next: RDB archiver disk space Jiro Fujita
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Custom file saving plugin in AreaDetector Hinko Kočevar
Next: Re: Custom file saving plugin in AreaDetector Hinko Kočevar
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024