LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview .net picture box 1172 error

Solved!
Go to solution

Hi all,

 

I have a small problem with my labview VI. I use a .Net picture box in my VI to display a bmp picture. I have a list of images that needs to be displayed and everytime I want to display an image, I use the Bitmap constructor by specifying the file path and get a bitmap reference and pass it to the picture box as shown in the image.

 

I have a list of around 50 images to show and during the process of showing everything (of course with time-delays between them), I get a .Net exception 1172 and its most probably from the Bitmap constructor. There is no problem with the path that I use to generate the bitmap instance. I have checked it and there is no fixed point in the experiment at which I get the error.

 

Sometimes, I get it at image 18, sometimes at 40 and sometimes at 50. But the list of images remain the same. Can somebody please help me as to how to go about solving this undeterministic error. I have attached a snapshot of the vi with this message. When I build an exe of the VI and run it without catching the exception, I get a message as shown in the txt file attached to this message. Appreciate any help 🙂

 

 

Thanks,

VJ

Download All
0 Kudos
Message 1 of 11
(5,356 Views)

vijay shankar wrote:

 

I get a .Net exception 1172 and its most probably from the Bitmap constructor.


Well, you don't have the error clusters wired to some of the .NET functions, so you're going to have a hard time tracking down which one is causing the error. I would suggest that you wire up all of the error clusters.

 

I also don't see any Close References.

 

I'm also a bit suspicious of those local variables floating around and those sequence frames. 

 

Care to upload your VI?

Message 2 of 11
(5,349 Views)

Hi,

 

Thanks for the response! I did not have immediate access to the VI yesterday since I left home. Here's the vi. I have also attached the snapshot of what piece of code is causing the problem since other parts of the vi may be unrelated. Please refer to the snapshot as to which part of the vi it is. 

 

The screenshot that I attached yesterday does the same as this and the problem is in both the VI's where I load pictures. Since this vi is smaller and more relevant, I have attached this. The vi connects to a server socket and then gets commands via the TCP connection established on that specified port with the server. This is more of a client vi, while the one that I pasted yesterday is the server where I generate the preview of the image that is shown in the client. 

 

This vi gets the name of a file. Appends it to an already established folder path which is also sent via the tcp connection initially and stored in a variable. The file path is then built using the folder path and the file name and I have attached probes for these wires and verified the data and found that it maps to a correct path present in the computer. The values of the probes in the screen shot are the one that the wires had when the application encountered the error.

 

Thanks a lot 🙂

-VJ

0 Kudos
Message 3 of 11
(5,326 Views)

Oops forgot to attach!! Here it is.

 

-VJ

Download All
0 Kudos
Message 4 of 11
(5,325 Views)

Even with the description you provided your code is very difficult to follow due to the poor structure. You've got local variables floating all over the place and meaningless/confusing control names. Why is a Boolean control called "filepath"? As I indicated you've got half of the .NET error clusters unwired, and you are not closing any of the references. You need to wire up your error clusters and close the references. Then you need to probe the error cluster(s) to find out which node is generating the error. Wiring up the error cluster will also allow you to remove the sequence frames.

 

Also, putting a long process inside an event case is bad. This locks up your event structure so it can't respond to any other events that may be generated on the front panel. Like somebody pressing a Stop button. Having two loops with an event structure in each one is not the way to solve this. You should look into the producer-consumer or master-slave architecture. 

Message 5 of 11
(5,309 Views)

Hi,

 

Thanks for your tips. I tried to wire the error clusters and noticed that the error 1172 was caused by the Bitmap constructor only. The message of the error reads "System.OutOfMemoryException". I guess this is because, the Bitmap objects that are created everytime are not deallocated from the memory and since I load around 50 images without setting the unused memory free, I guess I get this error. So now I have to do as you said, "Closing the references".

 

I am an expert programmer in C++, Java, but new to LabVIEW. I understand that I need to free unused memory, but I don't know where to. Because, I have to display an image until a new command from the server comes. Is there an in-built garbage collector in labview as in Java that I can invoke since I don't see labview doing it periodically as Java's JVM does for me. Or is there a way to store this reference in a pointer and free this space before I reallocate any memory to the same pointer. In c++, I would delete the pointer before going out of a function, but in labview, I cannot visualize it how to do. Is there something that would check if there is some memory being alloted previously so that, it can be deleted first and then re-allocate.

 

For e.g., I want to say

if(imagePointer != NULL) {

delete imagePointer;

}

//Then do allocation

 

Thanks & many kudos to you. 🙂

-VJ

0 Kudos
Message 6 of 11
(5,303 Views)
Once you close the reference the GarbageCollector should take care of releasing the memory. You can force the garbage collector to do its job by calling the GC.Collect() method. For instance, in your code you're loading a bitmap and then creating a second bitmap that's a resized version of the first. You no longer need the first bitmap, so you can close the reference and then do the garbage collection. You will need to experiment to determine where it would be best to perform the garbage collection.
Message 7 of 11
(5,288 Views)
There is one thing that confuses me: Why use the .NET PictureBox as opposed to the LabVIEW picture indicator? Had you tried the picture indicator and found that it could not do something?
0 Kudos
Message 8 of 11
(5,274 Views)

Hi, this sounds good.. I will definitely try this and let you know. 

About the picture box, I was searching in the internet on how to load a picture in labview from a file path. I first tried my hands-on with the picturebox and couldn't do this without knowing how to. But, once I knew about this .net picturebox, it was closely related to object oriented programming that I have been used to in Java and C++ and so it was so easy for me to set this up. 

 

I even tried to use the picture box when I encountered this problem, but all the examples I found couldn't help me do this. If you know how to load a picture with specified pixel sizes given a file path, could you please tell me? I would always love to know more! 🙂 Since I was in a hurry to get this done, I didn't do justice to pick this .net picture box instead of the picture box.

 

Thanks 🙂

 

-VJ 

0 Kudos
Message 9 of 11
(5,267 Views)
Solution
Accepted by topic author vijay shankar

Loading an image into a LabVIEW picture indicator is pretty easy. There are several VIs that can read GIF, PNG, or BMP files. A simple example of reading a PNG file and drawing the image into a picture indicator is attached. You can find lots of other examples in the LV Picture Control thread. (Note: Please do not post questions in that thread - it's meant to be a repository of links.)

Message 10 of 11
(5,251 Views)