diff --git a/libsecondlife-cs/AssetSystem/AssetManager.cs b/libsecondlife-cs/AssetSystem/AssetManager.cs index f1c8fc99..22813d8d 100644 --- a/libsecondlife-cs/AssetSystem/AssetManager.cs +++ b/libsecondlife-cs/AssetSystem/AssetManager.cs @@ -226,7 +226,7 @@ namespace libsecondlife.AssetSystem RequestXferPacket reply = (RequestXferPacket)packet; ulong XferID = reply.XferID.ID; - LLUUID AssetID = reply.XferID.VFileID; + // LLUUID AssetID = reply.XferID.VFileID; //Not used... // Setup to send the first packet curUploadRequest.LastPacketNumSent = 0; diff --git a/libsecondlife-cs/AssetSystem/ImageManager.cs b/libsecondlife-cs/AssetSystem/ImageManager.cs index fcc8b6cd..7534c3a9 100644 --- a/libsecondlife-cs/AssetSystem/ImageManager.cs +++ b/libsecondlife-cs/AssetSystem/ImageManager.cs @@ -30,6 +30,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading; using libsecondlife; using libsecondlife.Packets; @@ -62,6 +63,8 @@ namespace libsecondlife.AssetSystem private class TransferRequest { + public ManualResetEvent ReceivedHeaderPacket = new ManualResetEvent(false); + public bool Completed; public bool Status; public string StatusMsg; @@ -204,6 +207,11 @@ namespace libsecondlife.AssetSystem public bool isCachedImage(LLUUID ImageID) { + if (ImageID == null) + { + throw new Exception("Don't go calling isCachedImage() with a null..."); + } + switch (CacheType) { case CacheTypes.Memory: @@ -367,6 +375,9 @@ namespace libsecondlife.AssetSystem Array.Copy(Data, 0, tr.AssetData, tr.Received, Data.Length); tr.Received += (uint)Data.Length; + // Mark that the TransferRequest has received this header packet + tr.ReceivedHeaderPacket.Set(); + // If we've gotten all the data, mark it completed. if( tr.Received >= tr.Size ) { @@ -414,6 +425,9 @@ namespace libsecondlife.AssetSystem // FIXME: Sometimes this gets called before ImageDataCallbackHandler, when that // happens tr.AssetData will be null. Implimenting the above TODO should fix this. + // Wait until we've received the header packet for this image, which creates the AssetData array + tr.ReceivedHeaderPacket.WaitOne(); + // Add this packet's data to the request. Array.Copy(reply.ImageData.Data, 0, tr.AssetData, tr.BaseDataReceived + (1000 * (reply.ImageID.Packet - 1)), reply.ImageData.Data.Length); tr.Received += (uint)reply.ImageData.Data.Length; diff --git a/libsecondlife-cs/InventorySystem/InventoryManager.cs b/libsecondlife-cs/InventorySystem/InventoryManager.cs index c7d441eb..84e7d217 100644 --- a/libsecondlife-cs/InventorySystem/InventoryManager.cs +++ b/libsecondlife-cs/InventorySystem/InventoryManager.cs @@ -43,8 +43,6 @@ namespace libsecondlife.InventorySystem /// public class InventoryManager { -// private const bool DEBUG_PACKETS = false; - // Reference to the SLClient Library private SecondLife slClient; @@ -385,7 +383,7 @@ namespace libsecondlife.InventorySystem { if (htFolderDownloadStatus.Count == 0) { - DescendentRequest dr = (DescendentRequest)alFolderRequestQueue[0]; + DescendentRequest dr = alFolderRequestQueue[0]; alFolderRequestQueue.RemoveAt(0); RequestFolder(dr); } diff --git a/libsecondlife-cs/examples/IA_TestAsyncImage/IA_TestAsyncImage.cs b/libsecondlife-cs/examples/IA_TestAsyncImage/IA_TestAsyncImage.cs index 97553e3b..88c45191 100644 --- a/libsecondlife-cs/examples/IA_TestAsyncImage/IA_TestAsyncImage.cs +++ b/libsecondlife-cs/examples/IA_TestAsyncImage/IA_TestAsyncImage.cs @@ -72,7 +72,7 @@ namespace IA_TestAsyncImage { foreach (TextureEntryFace tef in avatar.Textures.FaceTextures.Values) { - if (imgManager.isCachedImage(avatar.FirstLifeImage) == false) + if (imgManager.isCachedImage(tef.TextureID) == false) { imgManager.RequestImageAsync(tef.TextureID); } @@ -136,14 +136,20 @@ namespace IA_TestAsyncImage } else { - Console.WriteLine("Finished ( " + data.Length + "): " + ImageID); + if (data == null) + { + Console.WriteLine("Image Data is null: " + ImageID); + } + else + { + Console.WriteLine("Finished ( " + data.Length + "): " + ImageID); - String filename = Path.Combine(OutputDirectory, ImageID.ToStringHyphenated()) + ".tif"; - - TiffJob tj = new TiffJob( filename, data ); - Thread t = new Thread(tj.RunMe); - t.Start(); + String filename = Path.Combine(OutputDirectory, ImageID.ToStringHyphenated()) + ".tif"; + TiffJob tj = new TiffJob(filename, data); + Thread t = new Thread(tj.RunMe); + t.Start(); + } } }