Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, February 27, 2006 10:37:25 AM(UTC)

travich  
travich

Groups: Registered
Posts: 14


I'm having an issue where, on the first retrieval of an image, the object comes out as it should.  On the second retrieval of an image from a hashtable, the image is castable as an image object, but throws a NullReferenceException when you try to set it to the image viewer.  If I look at the image properties, they all throw NullReferenceException errors. 

Again, one big clue is that I can retrieve an image the first time without this occurring.  Any help would be awesome!

Code that I'm currently using when loading the image.  The second time we grab the image is when the NullReferenceException is thrown:

private void LoadImage(string fileName)

{

IRasterImage Image;

object imgObj;

if (imageHash.ContainsKey(fileName))

{

imgObj = imageHash[fileName];

Image = (IRasterImage)imgObj;

}

else

{

Image = codecs.Load(fileName);

}

 

try

{

if (Image != null)

{

Viewer.Image = Image;

}

}

catch(Exception e)

{

MessageBox.Show(e.Message.ToString(), "Let Me Guess - Another Stupid NullReferenceException");

}

}

 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Tuesday, February 28, 2006 2:44:10 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

Hello,

What is the build number of LEADTOOLS.Net DLLs that you use?
What is the exact line in your code the fires the problem?

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#3 Posted : Tuesday, February 28, 2006 4:52:45 AM(UTC)

travich  
travich

Groups: Registered
Posts: 14


This is where the code dies:

Viewer.Image = Image;

It's version 14.5 and it's the Eval version.  We're just trying to decide if this is the component that we want to use or not...

 

travich attached the following image(s):
error.JPG
 
#4 Posted : Tuesday, February 28, 2006 6:25:38 AM(UTC)

travich  
travich

Groups: Registered
Posts: 14


Wow, I get this error even when I don't have a hash table in a seperate thread.  Someone else should try this and see if I'm losing my mind. Surely someone has seen this before.

Here's my LoadHash code, am I doing something wrong?  I wouldn't think so since I can initially retrieve a value from the hashtable.

private void LoadHash()
{

   IRasterImage img;
   
RasterCodecs c = new RasterCodecs();

   foreach (string f in Files)
   {
      img = c.Load(f.ToString());
      imageHash.Add(f.ToString(), img);
    
}

   return;

}

 
#5 Posted : Tuesday, February 28, 2006 8:53:51 AM(UTC)

travich  
travich

Groups: Registered
Posts: 14


I'm on to something, but have a workaround. 

Here's my thoughts:

IRasterImage appears to be managed code, so this shouldn't be a problem.  It's also not a com object.  My thinking is what is happening is that the IRasterImage is actually storing a reference to that image.  When I pull it from the hashtable, I'm actually copying over the reference, not the actual value.  After the image is set to the viewer or at some point in the scope, the image dies and since it's actually pointing to the reference, the values pointed to through the reference die too.  The hashtable still thinks the image exists, and will retrieve the object even though it's actually dead (the pointer still exists as well as the key). 

Workaround for hashtable retrieval:

//Call the clone() method and actually "copy" the value.
Image = ((
IRasterImage)imageHash[fileName]).Clone();

 

What does everyone think of my hypothesis? 

 
#6 Posted : Wednesday, March 1, 2006 4:20:44 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

Hello,

I think it's a good solution. Did you try this workaround? If yes, what was the result?

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#7 Posted : Wednesday, March 1, 2006 5:08:05 AM(UTC)

travich  
travich

Groups: Registered
Posts: 14


Yes it did.
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.079 seconds.