LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview crashes entirely when passing a buffer to sub-vi

I need to pass a varying length buffer of unsigned 8-bit values to a sub-vi.  Most times it works, but it often crashes Labview entirely.  Everything related to Labview just goes away - no error message from Labview.  Windows reports an attempt  at an out-of-bounds memory access.

When I single step the main vi, the crash occurs just as I attempt to step into the sub-vi.

It appears that Labview wants to "pass by value" when sending the buffer to the sub-vi for action, but this is a problem if the length of the buffer can vary.  Is there a way to pass a buffer to a sub-vi by location, rather than by value?
0 Kudos
Message 1 of 5
(3,078 Views)

hi there

if there are any dll- or CIN- calls involved in your code, check them first! it's quite hard to kill labview with pure G-code, in most cases real chrashes are produced by external code or faulty interfaces between LV and the external code.

another common reason for crashes or at least abort of execution are wrong calculated sizes of arrays (an array-element index out of boundaries will NOT lead to a crash), i.g. if you calculate the new size of the array with division by zero LV may crash or at least abort execution.

you could also save the contents of the array to a file befor the data enters the sub-vi. maybe you find a hint to the error in the data.

another reason could be a corrupted VI.

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 2 of 5
(3,068 Views)
Yeah, the problem isn't in the sub-vi.  It does call an external DLL, but it dies just as I step into it, not when actually executing the sub-vi.  The sub-vi contains a stacked sequence structure, and it does a few things prior to calling any external code, like calculate a checksum and length.  So there is (simple) code I should be able to step through before the dll call is actually invoked.

From the way Labview is acting, and the exact timing of the crash, I am fairly certain that the problem is that the sub-vi has to take an array of unsigned 8 bit values of unknown length.  In the sub-vi, the array variable that accepts this buffer is initialized with 0 length, or no members.  In C, I could pass a pointer to the buffer.  I can create a reference to the array in the calling vi, but I don't know what kind of "receptacle" to create in the sub-vi to accept a pointer to the array.

I've been thinking about it, and what I'm going to try is this:  For each vi that uses the sub-vi, the variable name for the buffer will always be "buffer".  From the sub-vi, I can then refer back to the calling vi, to a variable called "buffer".  I do this in a lot of other vis that I've written with great success.   (For example, when I want to break a complex part of a main vi out to a sub-vi in order to simplify things, but I still want to interact in real time with controls and indicators.  The downside is that I errors in the sub-vi don't always get detected by Labview until runtime, and the runtime errors don't provide a lot of information - i.e. debugging becomes more difficult.)

I'll post back on the results.

-M

Message 3 of 5
(3,062 Views)
Well, it gets better.   The crashes all seem to be occurring when my buffers (arrays of unsigned 😎 are being manipulated.  I got crashes when trying to determine size, when building to size, etc.  I find them by setting breakpoints and doing a "successive approximation".  Then I can't reproduce the errors during single-step operation - only at full speed.  This includes when I set a breakpoint on the offending array operation and manually "unpausing" execution.

I did a google search on the address of the offending function, and the only hit was a previous thread here.  That thread steered blame toward a call to an external DLL.  Interestingly, they were attempting to do string operations in a vi that called an external library, like me.  (Well, my "buffers" are little different from strings, really)

What finally seems to have fixed it was adding 1mSec delays after certain operations on the buffer, such as adding elements or allocating space in an array of zeros.  A time delay?  Why does this fix it?  Would it have anything to do with declaring the function to be "reentrant", rather than "run in UI thread"???

-M
0 Kudos
Message 4 of 5
(3,044 Views)
********* Please Disregard: I posted in the wrong thread **********
I know this is an old thread, but I hope someone is still monitoring it. 

I have also experinced a similar problem in LV 8.2.  My CIN function (simple function to add 2 numbers) works just fine on my PC host computer but when I try to run it on my cRIO RT target, it would not work.  The CIN in in a loop and when the program try to execute the CIN the loop breaks and the VI halts without giving an error. 

Regards,
NDo


Message Edited by ndo on 01-09-2008 06:40 PM
0 Kudos
Message 5 of 5
(2,850 Views)