LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Nifpga.dll - resources leak - unload problem

Hello All,

 

This post is some kind bug report.

I'm not sure if this place is a best place to report my problem. If not, please move to correct section.

 

At the beginning, we have project that we use NI PCIe-7852R, to control some external devices like scanners etc. So we have prepared FPGA firmware that works fine. Our fpga is controlled/configured/setup from PC. It means that we can setup some user-defined values. This part works fine as well.

 

So, in our system configuration looks like this:

- NI LabView(fpga) generates firmware fpga.lvbitx

- Using C API generator we create headers, for this firmware

- Using C API, we create c++ wrapper

- Using C++ wrapper we port this functionality to python.

- User use python to setup NI fpga.

 

Ok, everything looks correct, and works for first look. Problems starts when we finishing work with fpga, and when we start releasing resources. (of course our project is bigger than python which controls ni fpga, but it doesn't matter). We notices that  when we start using NI C(fpga) API, then our other library are not unloaded correctly. Destructors on our libraries are not called. It look's like python terminate working without releasing our libraries. To cut off from our application I prepared small Visual Studio application that you "can reproduce" this issue.

 

In attached file you can find source codes, that you need to compile.

Code is very simple, it contains only 4 line with logic, so it is as simple as it can be.

There is also bit file(fpga.lvbitx), just for upload and test application.

 

How to reproduce problem?

- please make sure that you have PCIe NI-7852R board on you PC

- open solution and compile program

- run program NiFpgaDtor.exe - everything looks good.

- next download Application Verifier(x64).

- run application verifier and add "NiFpgaDtor.exe" file

- click save

- close application verifier

- run again application verifier and check if NiFpgaDotr.exe was added correctly.

- run program NiFpga.exe again. Now you noticed crash, because application throw exception about leak.

 

Additional information is, when we only load nifpga.dll and unload without using resources, there is no problem. Problem start when we use NiFpga_Open(...)/NiFpga_Close() functions.

 

Version of NiFpga.dll that we use is 17.0.0.49152.

OS: Windows 10 x64.

 

Could anyone from National Instruments work with it and confirm that there is problem on NI side?

I'm glad to help you to find solution, or test your fixed version.

 

Best regards,

Bartek

 

 

0 Kudos
Message 1 of 7
(3,371 Views)

I attached missed .zip file.

0 Kudos
Message 2 of 7
(3,370 Views)

Have you verified that the many layers of wrapper code from Python down to C are being called correctly? If you are using Python's __del__ functionality, are those destructors getting called? Are the C++ destructors getting called. It would be good to double-check that the Close operations on the C API are indeed getting called properly.

0 Kudos
Message 3 of 7
(3,361 Views)

Thanks for fast response.

 

I wrote whole my setup, just in case. But in my case it really doesn't matter. All destructor calls are good when use ni fpga wrapper, but I didn't call Nifpga_open() inside wrapper(which allocate resources of fpga board). So rest of the code are correct. As I said, to cut off from my application, I prepared just small application(Pure C++) that use nifpga.dll and there is a leak in this dll.

 

0 Kudos
Message 4 of 7
(3,296 Views)

Previous zip file contains solution with Visual Studio 2015 ToolSet's. So there is a chance that you cannot open it on earlier version of Visual Studio. In attachments, I prepared the same source codes, but solution if configured to Visual Studio 2010. It means that it will be working with VS2010 or newer(you just need to update libraries when Visual Studio will ask you.).

0 Kudos
Message 5 of 7
(3,218 Views)

This problem can be also replicated(shown) by using NI example code downloaded from here:

http://www.ni.com/tutorial/8638/en/

 

In attachments you can find application verifier configuration, and screenshot with call stack and debugger output information.

 

Best,

Bartek

 

 

 

0 Kudos
Message 6 of 7
(3,199 Views)

Hi everyone,

 

I attached VS solution with projects that can clearly shows behavior that I noticed using python.

Solution is made only in c++, so there is not excuses that python do anything wrong.

 

So, solution contains 3 projects:

1) NiFpgaWrapper that is only wrapper for NiFpga calls,

2) CustomModule, which generate DLL,

3) NiFpgaDtor application project, which is simple usage of above projects.

 

When you compile solution you can see, that object "CustomClass" from CustomModule.dll is created, but destructor of this object is never called. However, when you go to NiFpgaWrapper Project, a there comment two lines with NiFpga_Open(...) and NiFpga_Close(...), (and next recompile projects,) then you see, that destructor from CustomModule.dll is called as it is expected.

 

Best,

Bartek

 

 

0 Kudos
Message 7 of 7
(3,121 Views)