LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Initializes an array and passes as a pointer causes labview to crash

I am have a shared library and in my VI I am calling this function:

 

DWORD WINAPI ReadFrames (signed int* timeDomainBuffer, signed int* frequencyDomainBuffer, DWORD timeDomainBufferElements, DWORD frequencyDomainBufferElements,

DWORD* timeDomainFramesRead, /DWORD* frequencyDomainFramesRead, DWORD timeDomainTranspose, DWORD wait);

Forum Picture.png

 

 I am passing an array of size 10240 into timeDomainBuffer. The 10240 constant is going into timeDomainBufferElements.

This is causing labview to crash whenever I run the program. I believe it has to do with the way I am allocating memory. Any help is appreciated.

0 Kudos
Message 1 of 14
(3,514 Views)

No.  You have an auto-indexing tunnel at the For Loop which means you are getting a single scalar elemetn on each loop iteration, and that is what is being passed into the subVIs.

 

The reduced size of your image is making it hard to see, and not having actual VI's or the subVI's makes it impossible to know what is going on in those subVI's and whether the calls to the dll are setup correctly.  (My guess is no.)

0 Kudos
Message 2 of 14
(3,487 Views)

For this function (Read Frames):

 

Calling Convention: stdcall

timeDomainBuffer:

Control Type: Numeric

Pass Type: Pass by pointer

Representation: Long

 

If I fix where I pass the array to the function it might work?

Download All
0 Kudos
Message 3 of 14
(3,474 Views)

I just realized that Labview must handle pointers in a different way. I needed to change that parameter to pass by array instead of pass by pointer.

0 Kudos
Message 4 of 14
(3,445 Views)

@User002 wrote:

I just realized that Labview must handle pointers in a different way. I needed to change that parameter to pass by array instead of pass by pointer.


That's not correct. You need to pass the entire array rather than a single integer. And configure the parameter as array passed as data pointer. LabVIEW does not use pointers on its diagram. Due to the autoindexing you are passing an array element into the function and tell the DLL function to treat it as a pointer => hard crash as the DLL function tries to dereference a value that is not a valid memory address.

 

The function prototype you show is unfortunately not very conclusive as to what the function really requires. Don't you need to provide a buffer for the frequencyDomainBuffer parameter too?

 

Also saving the VIs for a previous LabVIEW version would help as not everybody has LabVIEW 2015 installed on all machines.

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 14
(3,404 Views)

Well I got rid of the for loop so it actually is not auto-indexing. Also there is no parameter for array passed as pointer, just pass by pointer and pass by array. If pass by array is an array passed as a pointer than I am unsure why you said I was wrong.

 

Also, I do not need to provide a buffer for the frequencyDomainBuffer because I am not using the frequency domain right now.

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

@User002 wrote:

For this function (Read Frames):

 

Calling Convention: stdcall

timeDomainBuffer:

Control Type: Numeric

Pass Type: Pass by pointer

Representation: Long

 

If I fix where I pass the array to the function it might work?


This should be

 

Control Type: Array

Data Type: Signed 32 bit integer

Dimensions: 1

Array format: Array Data Pointer

Minmum Size: either leave at <None> and make sure to use an Initialize Array function to create an array as long as necessary or set this to "timeDomainBufferElements"

 

If the frequencyDomainBuffer parameter can be indeed left empty (we don't know and the C prototype can't tell if that is the case but this would need to be seperately documented in the library documentation) then you should probably configure this parameter as pointer sized integer and wire a 0 to it, and also make sure to wire a 0 to frequencyDomainBufferElements.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 14
(3,347 Views)

Control type: array is not an option in the Import Shared Library wizard - Configure VIs and Controls

0 Kudos
Message 8 of 14
(3,332 Views)

Then don't use the Wizard for this function but configure the Call Library Node yourself manually!

 

The Import Library Wizard can't do magic, despite the Wizard in its name. The C syntax of header files is notorously lacking information to describe a function interface fully. But it is the only standardized and machine parsable thing that exists for C function interfaces. The C syntax only provides barely enough information for the C compiler to do the right thing in terms of creating correct machine code, but it does not describe if a pointer variable is a scalar passed by reference, an array or possibly even a super duper object datatype.

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 14
(3,310 Views)

Ah okay that makes a lot of sense. If only the wizard did perform magic! Luckily for me, that is the only function that would require this. I am getting an error saying: One or more required inputs to this function are not wired or are wired incorrectly. Do all the inputs need to be wired to something, even if they are a pointer?

0 Kudos
Message 10 of 14
(3,296 Views)