LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

crash by invalid pointer

Solved!
Go to solution

Dear Community,

 

I have a problem with the transfer of data between LabView and my memory implementation as Library Function Node (dll). Quick to the build: two parallel while loops for acquisition and output tasks, I want to exchange data between both. First a storage  (ring buffer) is initialized for this exchange. Reading and writing use array data pointers.

Write: the array data pointer (Input Node) is used to create a copy in the memory

Read: an array data pointer of LabView (Input Node) is used and the data of memory will be transferred (Output Node)

 

A debug report has revealed that apparently invalid pointer as 0x00000000 and 0xFFFFFFFF have passed. The Error is a bit hard to describe because LabView closes instantly or registers a bug, trying to debug and then requests for close programm. The crashes appear completely random, sometimes after a long measurement, sometimes at closure of tasks (not at first call) , sometimes during initialization (not the first call). In addition, it seems that the first call of VI doesn't produce crashes. It seems the memory interferes with LabView and thus produce error in LabViews memory. Does anyone have experience with the memory management of LabView and can tell when a memory would receive the pointer 0x000000000 oder 0xFFFFFFFF? Have shiftregister and global variables always a fixed address or are they managed dynamically? Is it possible that LabView gives array data pointer impermissible values, so the dll tries to get the data with an invalid pointer?

 

Memory without acquisition and ouput task works fine. Only when add tasks, LabView crashes as described.

 

I am grateful for any help!

0 Kudos
Message 1 of 8
(6,472 Views)

Really hard to debug code without seeing the code.  Attach your VI (do NOT attach a picture of the Block Diagram -- we need "Code we can Closely Inspect/Edit/Run".  If you have multiple VIs, compress the Folder they are in (use "Send to" option on folder, choosed Compressed) to make a Zip file of the Folder and its contents, a single file you can attach.

 

Bob Schor

0 Kudos
Message 2 of 8
(6,450 Views)
Solution
Accepted by topic author VS_03

Problem solved, the length of structs was different to the calculated. Set "pack=1" helped.

0 Kudos
Message 3 of 8
(6,381 Views)

@VS_03 wrote:

Problem solved, the length of structs was different to the calculated. Set "pack=1" helped.


Can someone explain what Set "pack=1" means?

 

I know this is an old solution, but I have similar symptoms with a persistent frustrating crash with LV2017 64-bit, and just finished using WinDbg to get more information about it (see below).

Was hoping to try this, but could not get any google hits for Labview "set pack=1".

Help?

 

EXCEPTION_RECORD: (.exr -1)
ExceptionAddress: 00007ffa64fb862c (mgcore_SH_17_0!aligned_free+0x000000000000737c)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 0000000000000000
Parameter[1]: ffffffffffffffff
Attempt to read from address ffffffffffffffff

PROCESS_NAME: LabVIEW.exe

0 Kudos
Message 4 of 8
(4,762 Views)

This is a setting also commonly called alignment. Basically there are two different ways to define the structure alignment of structure elements.

 

First you have the global settings of the C compiler. Here you select what the C compiler should use if nothing else is specified in the source code. In Visual Studio it can depend on the version you are using but generally it is in the project settings under C/C++/Code Generation/Struct Member Alignment or something similar. This is default set to "Default" (sigh) which for Visual Studio is 8 byte.

 

Then you have the #pragma pack() compiler directive which can be used to change the alignment (temporarly) to a different explicit value. Under Windows 32-bit (and Pharlap) LabVIEW uses 1 byte alignment, under all other current platforms it uses the default alignment which for Windows 64-bit is hence 8-byte as LabVIEW is compiled with Visual Studio. Please note that other compilers might use a different default alignment. Anything that can be configured with #pragma's is generaly compiler specific, even the syntax is often totally different.

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 8
(4,749 Views)

Thank you, rolfk.

So it seems like it was in the way the OP compiled his dll, with his c compiler, and in my situation (vanilla LabVIEW 64-bit 2017.0.0) it's not the same thing after all even though the LV crash debug indicated a similar cause.

Bummer.

 

Ok - thanks! If I can't figure this out, I'll post a new thread.

0 Kudos
Message 6 of 8
(4,738 Views)

The Access Violation exception is a VERY generic exception. The CPU generates this whenever an instruction tries to access memory addresses that are not mapped into the current process. The reason for such an error are manifold and bad alignment of memory elements in structs is just one of many possible reasons for such an error.

Other possible errors are outright bugs in the DLL itself (or in LabVIEW but that is fairly unlikely), misconfigurations of the Call Library Nodes in respect to what the DLL interface really should need, and the most common one, data buffers that the DLL tries to write into but that the caller hasn't allocated (long enough). This last one is something LabVIEW can't do for you automatically as it has no way of knowing that a particular parameter is meant to be a memory buffer with a certain minimum size, and even less what that size should be. It could of course assume that any such buffer might need 1GB of memory, just to be almost always safe (well even 1GB could be not enough in certain situations) and everybody then starts to scream havoc why LabVIEW is so crazy inefficient with memory whenever you throw in that VI that contains a Call Library Node which takes such a parameter, so it's clearly not an option!

The person who programs the VI with the Call Library Node has to do that explicitly just as any C programmer has to do who tries to call that API!

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 8
(4,711 Views)

Ah, but I'm not using a Call Library Node in any of my code. Any library calls are in NI code, not mine. 

Only reason I found this thread was because of the 0xffffffffffffffff bad pointer error, not because of call library usage (this may not have been clear from my "similar problem" post above).

 

I'm convinced now it's either LabVIEW 64bit bug (an old one that's probably been addressed, and only appears sometimes), or some subtle bit of corruption that crept in on my system. Not only crashing while my program ran, but crashing when I click the Save button (particularly evil, that) and when I click properties for a front panel control. After doing a good bit of troubleshooting, then doing two full uninstall/manual registry key deletions/reinstalls, it persisted. 

 

However, once I went from LV2017 64-bit to LV2017 32-bit SP1 it seems to have stopped crashing.

Had to regenerate a lossy stream channel when I did that, now wondering if that channel had gotten corrupted and was causing some of my problems. I've really regretted my decision to use these newfangled channels on this project. After my intial problems I just kept on because I don't want to be a reactionary fogey, but they've cost me  many hours. 

 

In any case, my problem (so far) was solved by not using the 64-bit version of LabVIEW 2017 any more. 

0 Kudos
Message 8 of 8
(4,694 Views)