J
John Hatpin
Another somewhat newbie question about C# processing stopping in the
middle of code. I've pasted in a section of code at the end of this
post which illustrates the problem. For ease of reading, I've replaced
tabs with spaces by hand - I think I've got that right.
Within the code, I have debug.write statements, which show where the
processing is failing. This section of code is called repeatedly, with
different data, and almost never reaches the end. It usually stops
after having printed either "4" or "c", outputting eg:
....12341234abcabcabcabc12341234...
1, 2 and 3 are output earlier in the code. "5" is almost never
printed, despite many hundreds of runs through with different data.
I appreciate that the code is not good - there are multiple tests for
nulls in the TEF object which are probably unnecessary, for example -
but I'm working without any documentation and I'd rather test every
condition than have it fail silently (see below).
Now, obviously this is only a small part of the app. Some of those
calls are to library methods which I don't even have the source for.
However, there is something I'm fundamentally not understanding here.
How can, for example, the line printing "c" be run, but not the line
printing "d"? All that's in between them is the closing brace for the
foreach() block - if it executes the contents of the foreach, then why
does it not execute the statement after?
(On a personal note, I do find it extremely frustrating and
demotivating that C# code just stops like this without producing any
kind of error message, even run (as in this case) in debug mode. The
only reason I knew to start looking for a problem in the first place
was because I saw symptoms of later code (after the "5") not being
run. This seems to be normal behaviour, this silent failing, but I do
find it maddening.)
The environment is Windows XP Home, SharpDevelop and everything
up-to-date.
Thanks in advance for your help.
System.Diagnostics.Debug.Write("4") ;
lock(Prim)
{
if (!Prim.Textures.Equals(null))
{
if (Prim.Textures.FaceTextures.Length > 0)
{
foreach(Primitive.TextureEntryFace TEF in
Prim.Textures.FaceTextures)
{
if (!TEF.Equals(null))
{
if (!TEF.TextureID.Equals(null))
{
if (TEF.TextureID != UUID.Zero)
{
System.Diagnostics.Debug.Write("a") ;
Texture T = InsertOrSelectTexture(TEF.TextureID) ;
if (!tItem.FaceTextures.Contains(T))
tItem.FaceTextures.Add(T) ;
Client.Assets.RequestImage(TEF.TextureID, UpdateTexture)
;
if (!T.Items.Contains(tItem))
T.Items.Add(tItem) ;
System.Diagnostics.Debug.Write("b") ;
}
}
}
System.Diagnostics.Debug.Write("c") ;
}
System.Diagnostics.Debug.Write("d") ;
}
}
}
System.Diagnostics.Debug.Print("5") ;
middle of code. I've pasted in a section of code at the end of this
post which illustrates the problem. For ease of reading, I've replaced
tabs with spaces by hand - I think I've got that right.
Within the code, I have debug.write statements, which show where the
processing is failing. This section of code is called repeatedly, with
different data, and almost never reaches the end. It usually stops
after having printed either "4" or "c", outputting eg:
....12341234abcabcabcabc12341234...
1, 2 and 3 are output earlier in the code. "5" is almost never
printed, despite many hundreds of runs through with different data.
I appreciate that the code is not good - there are multiple tests for
nulls in the TEF object which are probably unnecessary, for example -
but I'm working without any documentation and I'd rather test every
condition than have it fail silently (see below).
Now, obviously this is only a small part of the app. Some of those
calls are to library methods which I don't even have the source for.
However, there is something I'm fundamentally not understanding here.
How can, for example, the line printing "c" be run, but not the line
printing "d"? All that's in between them is the closing brace for the
foreach() block - if it executes the contents of the foreach, then why
does it not execute the statement after?
(On a personal note, I do find it extremely frustrating and
demotivating that C# code just stops like this without producing any
kind of error message, even run (as in this case) in debug mode. The
only reason I knew to start looking for a problem in the first place
was because I saw symptoms of later code (after the "5") not being
run. This seems to be normal behaviour, this silent failing, but I do
find it maddening.)
The environment is Windows XP Home, SharpDevelop and everything
up-to-date.
Thanks in advance for your help.
System.Diagnostics.Debug.Write("4") ;
lock(Prim)
{
if (!Prim.Textures.Equals(null))
{
if (Prim.Textures.FaceTextures.Length > 0)
{
foreach(Primitive.TextureEntryFace TEF in
Prim.Textures.FaceTextures)
{
if (!TEF.Equals(null))
{
if (!TEF.TextureID.Equals(null))
{
if (TEF.TextureID != UUID.Zero)
{
System.Diagnostics.Debug.Write("a") ;
Texture T = InsertOrSelectTexture(TEF.TextureID) ;
if (!tItem.FaceTextures.Contains(T))
tItem.FaceTextures.Add(T) ;
Client.Assets.RequestImage(TEF.TextureID, UpdateTexture)
;
if (!T.Items.Contains(tItem))
T.Items.Add(tItem) ;
System.Diagnostics.Debug.Write("b") ;
}
}
}
System.Diagnostics.Debug.Write("c") ;
}
System.Diagnostics.Debug.Write("d") ;
}
}
}
System.Diagnostics.Debug.Print("5") ;