From bdc13455011c9de2877813138a49d83fc52d3142 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 2 Oct 2009 13:08:15 -0700 Subject: * Removed even more unnecessary state variables from J2KImage * Fixed the incorrect "out of memory?" exception messages and replaced them with useful information * Cleaned up J2KImage and LLImageManager to conform to coding conventions --- OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs | 278 +++++++++------------ .../Region/ClientStack/LindenUDP/LLImageManager.cs | 46 ++-- 2 files changed, 142 insertions(+), 182 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs b/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs index 5f549b5..0e3630c 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs @@ -47,69 +47,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - public uint m_lastSequence; - public float m_requestedPriority; - public uint m_requestedPacketNumber; - public sbyte m_requestedDiscardLevel; - public UUID m_requestedUUID; - public IJ2KDecoder m_j2kDecodeModule; - public IAssetService m_assetCache; - public OpenJPEG.J2KLayerInfo[] m_layers; - public bool m_decoded; - public bool m_hasasset; - public C5.IPriorityQueueHandle m_priorityQueueHandle; - - private uint m_packetNumber; - private bool m_decoderequested; - private bool m_asset_requested; - private bool m_sentinfo; + public uint LastSequence; + public float Priority; + public uint StartPacket; + public sbyte DiscardLevel; + public UUID TextureID; + public IJ2KDecoder J2KDecoder; + public IAssetService AssetService; + public OpenJPEG.J2KLayerInfo[] Layers; + public bool IsDecoded; + public bool HasAsset; + public C5.IPriorityQueueHandle PriorityQueueHandle; + + private uint m_currentPacket; + private bool m_decodeRequested; + private bool m_assetRequested; + private bool m_sentInfo; private uint m_stopPacket; - private AssetBase m_asset; - private int m_assetDataLength; + private byte[] m_asset; private LLImageManager m_imageManager; - #region Properties - - public uint m_pPacketNumber - { - get { return m_packetNumber; } - } - public uint m_pStopPacketNumber - { - get { return m_stopPacket; } - } - - public byte[] Data - { - get - { - if (m_asset != null) - return m_asset.Data; - else - return null; - } - } - - public ushort TexturePacketCount() - { - if (!m_decoded) - return 0; - - try - { - return (ushort)(((m_assetDataLength - FIRST_PACKET_SIZE + IMAGE_PACKET_SIZE - 1) / IMAGE_PACKET_SIZE) + 1); - } - catch (Exception) - { - // If the asset is missing/destroyed/truncated, we will land - // here - // - return 0; - } - } - - #endregion Properties - public J2KImage(LLImageManager imageManager) { m_imageManager = imageManager; @@ -117,33 +74,32 @@ namespace OpenSim.Region.ClientStack.LindenUDP public bool SendPackets(LLClientView client, int maxpack) { - if (m_packetNumber <= m_stopPacket) + if (m_currentPacket <= m_stopPacket) { bool SendMore = true; - if (!m_sentinfo || (m_packetNumber == 0)) + if (!m_sentInfo || (m_currentPacket == 0)) { if (SendFirstPacket(client)) { SendMore = false; } - m_sentinfo = true; - m_packetNumber++; + m_sentInfo = true; + m_currentPacket++; } - // bool ignoreStop = false; - if (m_packetNumber < 2) + if (m_currentPacket < 2) { - m_packetNumber = 2; + m_currentPacket = 2; } int count = 0; - while (SendMore && count < maxpack && m_packetNumber <= m_stopPacket) + while (SendMore && count < maxpack && m_currentPacket <= m_stopPacket) { count++; SendMore = SendPacket(client); - m_packetNumber++; + m_currentPacket++; } - if (m_packetNumber > m_stopPacket) + if (m_currentPacket > m_stopPacket) return true; } @@ -156,68 +112,68 @@ namespace OpenSim.Region.ClientStack.LindenUDP //and assign the real discardLevel and packetNumber //assuming of course that the connected client might be bonkers - if (!m_hasasset) + if (!HasAsset) { - if (!m_asset_requested) + if (!m_assetRequested) { - m_asset_requested = true; - m_assetCache.Get(m_requestedUUID.ToString(), this, AssetReceived); + m_assetRequested = true; + AssetService.Get(TextureID.ToString(), this, AssetReceived); } } else { - if (!m_decoded) + if (!IsDecoded) { //We need to decode the requested image first - if (!m_decoderequested) + if (!m_decodeRequested) { //Request decode - m_decoderequested = true; + m_decodeRequested = true; // Do we have a jpeg decoder? - if (m_j2kDecodeModule != null) + if (J2KDecoder != null) { - if (Data == null) + if (m_asset == null) { - J2KDecodedCallback(m_requestedUUID, new OpenJPEG.J2KLayerInfo[0]); + J2KDecodedCallback(TextureID, new OpenJPEG.J2KLayerInfo[0]); } else { // Send it off to the jpeg decoder - m_j2kDecodeModule.BeginDecode(m_requestedUUID, Data, J2KDecodedCallback); + J2KDecoder.BeginDecode(TextureID, m_asset, J2KDecodedCallback); } } else { - J2KDecodedCallback(m_requestedUUID, new OpenJPEG.J2KLayerInfo[0]); + J2KDecodedCallback(TextureID, new OpenJPEG.J2KLayerInfo[0]); } } } else { // Check for missing image asset data - if (m_asset == null || m_asset.Data == null) + if (m_asset == null) { - // FIXME: - m_packetNumber = m_stopPacket; + m_log.Warn("[J2KIMAGE]: RunUpdate() called with missing asset data (no missing image texture?). Canceling texture transfer"); + m_currentPacket = m_stopPacket; return; } - if (m_requestedDiscardLevel >= 0 || m_stopPacket == 0) + if (DiscardLevel >= 0 || m_stopPacket == 0) { - int maxDiscardLevel = Math.Max(0, m_layers.Length - 1); + int maxDiscardLevel = Math.Max(0, Layers.Length - 1); // Treat initial texture downloads with a DiscardLevel of -1 a request for the highest DiscardLevel - if (m_requestedDiscardLevel < 0 && m_stopPacket == 0) - m_requestedDiscardLevel = (sbyte)maxDiscardLevel; + if (DiscardLevel < 0 && m_stopPacket == 0) + DiscardLevel = (sbyte)maxDiscardLevel; // Clamp at the highest discard level - m_requestedDiscardLevel = (sbyte)Math.Min(m_requestedDiscardLevel, maxDiscardLevel); + DiscardLevel = (sbyte)Math.Min(DiscardLevel, maxDiscardLevel); //Calculate the m_stopPacket - if (m_layers.Length > 0) + if (Layers.Length > 0) { - m_stopPacket = (uint)GetPacketForBytePosition(m_layers[(m_layers.Length - 1) - m_requestedDiscardLevel].End); + m_stopPacket = (uint)GetPacketForBytePosition(Layers[(Layers.Length - 1) - DiscardLevel].End); //I don't know why, but the viewer seems to expect the final packet if the file //is just one packet bigger. if (TexturePacketCount() == m_stopPacket + 1) @@ -230,7 +186,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP m_stopPacket = TexturePacketCount(); } - m_packetNumber = m_requestedPacketNumber; + m_currentPacket = StartPacket; } if (m_imageManager.Client.PacketHandler.GetQueueCount(ThrottleOutPacketType.Texture) == 0) @@ -242,20 +198,52 @@ namespace OpenSim.Region.ClientStack.LindenUDP } } + private bool SendFirstPacket(LLClientView client) + { + if (m_asset == null) + { + m_log.Warn("[J2KIMAGE]: Sending ImageNotInDatabase for texture " + TextureID); + client.SendImageNotFound(TextureID); + return true; + } + else if (m_asset.Length <= FIRST_PACKET_SIZE) + { + // We have less then one packet's worth of data + client.SendImageFirstPart(1, TextureID, (uint)m_asset.Length, m_asset, 2); + m_stopPacket = 0; + return true; + } + else + { + // This is going to be a multi-packet texture download + byte[] firstImageData = new byte[FIRST_PACKET_SIZE]; + + try { Buffer.BlockCopy(m_asset, 0, firstImageData, 0, FIRST_PACKET_SIZE); } + catch (Exception) + { + m_log.ErrorFormat("[J2KIMAGE]: Texture block copy for the first packet failed. textureid={0}, assetlength={1}", TextureID, m_asset.Length); + return true; + } + + client.SendImageFirstPart(TexturePacketCount(), TextureID, (uint)m_asset.Length, firstImageData, (byte)ImageCodec.J2C); + } + return false; + } + private bool SendPacket(LLClientView client) { bool complete = false; - int imagePacketSize = ((int)m_packetNumber == (TexturePacketCount())) ? LastPacketSize() : IMAGE_PACKET_SIZE; + int imagePacketSize = ((int)m_currentPacket == (TexturePacketCount())) ? LastPacketSize() : IMAGE_PACKET_SIZE; try { - if ((CurrentBytePosition() + IMAGE_PACKET_SIZE) > m_assetDataLength) + if ((CurrentBytePosition() + IMAGE_PACKET_SIZE) > m_asset.Length) { imagePacketSize = LastPacketSize(); complete = true; - if ((CurrentBytePosition() + imagePacketSize) > m_assetDataLength) + if ((CurrentBytePosition() + imagePacketSize) > m_asset.Length) { - imagePacketSize = m_assetDataLength - CurrentBytePosition(); + imagePacketSize = m_asset.Length - CurrentBytePosition(); complete = true; } } @@ -266,27 +254,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (imagePacketSize > 0) { byte[] imageData = new byte[imagePacketSize]; - try - { - Buffer.BlockCopy(m_asset.Data, CurrentBytePosition(), imageData, 0, imagePacketSize); - } + int currentPosition = CurrentBytePosition(); + + try { Buffer.BlockCopy(m_asset, currentPosition, imageData, 0, imagePacketSize); } catch (Exception e) { - m_log.Error("Error copying texture block. Out of memory? imagePacketSize was " + imagePacketSize.ToString() + " on packet " + m_packetNumber.ToString() + " out of " + m_stopPacket.ToString() + ". Exception: " + e.ToString()); + m_log.ErrorFormat("[J2KIMAGE]: Texture block copy for the first packet failed. textureid={0}, assetlength={1}, currentposition={2}, imagepacketsize={3}, exception={4}", + TextureID, m_asset.Length, currentPosition, imagePacketSize, e.Message); return false; } //Send the packet - client.SendImageNextPart((ushort)(m_packetNumber - 1), m_requestedUUID, imageData); - } - if (complete) - { - return false; - } - else - { - return true; + client.SendImageNextPart((ushort)(m_currentPacket - 1), TextureID, imageData); } + + return !complete; } catch (Exception) { @@ -294,6 +276,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP } } + private ushort TexturePacketCount() + { + if (!IsDecoded) + return 0; + + if (m_asset == null) + return 0; + + if (m_asset.Length <= FIRST_PACKET_SIZE) + return 1; + + return (ushort)(((m_asset.Length - FIRST_PACKET_SIZE + IMAGE_PACKET_SIZE - 1) / IMAGE_PACKET_SIZE) + 1); + } + private int GetPacketForBytePosition(int bytePosition) { return ((bytePosition - FIRST_PACKET_SIZE + IMAGE_PACKET_SIZE - 1) / IMAGE_PACKET_SIZE) + 1; @@ -301,9 +297,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP private int LastPacketSize() { - if (m_packetNumber == 1) - return m_assetDataLength; - int lastsize = (m_assetDataLength - FIRST_PACKET_SIZE) % IMAGE_PACKET_SIZE; + if (m_currentPacket == 1) + return m_asset.Length; + int lastsize = (m_asset.Length - FIRST_PACKET_SIZE) % IMAGE_PACKET_SIZE; //If the last packet size is zero, it's really cImagePacketSize, it sits on the boundary if (lastsize == 0) { @@ -314,12 +310,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP private int CurrentBytePosition() { - if (m_packetNumber == 0) + if (m_currentPacket == 0) return 0; - if (m_packetNumber == 1) + if (m_currentPacket == 1) return FIRST_PACKET_SIZE; - int result = FIRST_PACKET_SIZE + ((int)m_packetNumber - 2) * IMAGE_PACKET_SIZE; + int result = FIRST_PACKET_SIZE + ((int)m_currentPacket - 2) * IMAGE_PACKET_SIZE; if (result < 0) { result = FIRST_PACKET_SIZE; @@ -327,68 +323,32 @@ namespace OpenSim.Region.ClientStack.LindenUDP return result; } - private bool SendFirstPacket(LLClientView client) - { - // this means we don't have - if (Data == null) - { - client.SendImageNotFound(m_requestedUUID); - m_log.WarnFormat("[TEXTURE]: Got null Data element on a asset {0}.. and the missing image Data property is also null", m_requestedUUID); - return true; - } - // Do we have less then 1 packet's worth of data? - else if (m_assetDataLength <= FIRST_PACKET_SIZE) - { - // Send only 1 packet - client.SendImageFirstPart(1, m_requestedUUID, (uint)m_assetDataLength, m_asset.Data, 2); - m_stopPacket = 0; - return true; - } - else - { - byte[] firstImageData = new byte[FIRST_PACKET_SIZE]; - try - { - Buffer.BlockCopy(m_asset.Data, 0, firstImageData, 0, (int)FIRST_PACKET_SIZE); - client.SendImageFirstPart(TexturePacketCount(), m_requestedUUID, (uint)m_assetDataLength, firstImageData, 2); - } - catch (Exception) - { - m_log.Error("Texture block copy failed. Possibly out of memory?"); - return true; - } - } - return false; - } - private void J2KDecodedCallback(UUID AssetId, OpenJPEG.J2KLayerInfo[] layers) { - m_layers = layers; - m_decoded = true; + Layers = layers; + IsDecoded = true; RunUpdate(); } private void AssetDataCallback(UUID AssetID, AssetBase asset) { - m_hasasset = true; + HasAsset = true; if (asset == null || asset.Data == null) { if (m_imageManager.MissingImage != null) { - m_asset = m_imageManager.MissingImage; - m_assetDataLength = m_asset.Data.Length; + m_asset = m_imageManager.MissingImage.Data; } else { m_asset = null; - m_decoded = true; + IsDecoded = true; } } else { - m_asset = asset; - m_assetDataLength = m_asset.Data.Length; + m_asset = asset.Data; } RunUpdate(); diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs index a484fdf..d641b6c 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs @@ -45,7 +45,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP { public int Compare(J2KImage x, J2KImage y) { - return x.m_requestedPriority.CompareTo(y.m_requestedPriority); + return x.Priority.CompareTo(y.Priority); } } @@ -94,7 +94,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP // Do a linear search for this texture download lock (m_priorityQueue) - m_priorityQueue.Find(delegate(J2KImage img) { return img.m_requestedUUID == newRequest.RequestedAssetID; }, out imgrequest); + m_priorityQueue.Find(delegate(J2KImage img) { return img.TextureID == newRequest.RequestedAssetID; }, out imgrequest); if (imgrequest != null) { @@ -105,7 +105,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP try { lock (m_priorityQueue) - m_priorityQueue.Delete(imgrequest.m_priorityQueueHandle); + m_priorityQueue.Delete(imgrequest.PriorityQueueHandle); } catch (Exception) { } } @@ -116,29 +116,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP //Check the packet sequence to make sure this isn't older than //one we've already received - if (newRequest.requestSequence > imgrequest.m_lastSequence) + if (newRequest.requestSequence > imgrequest.LastSequence) { //Update the sequence number of the last RequestImage packet - imgrequest.m_lastSequence = newRequest.requestSequence; + imgrequest.LastSequence = newRequest.requestSequence; //Update the requested discard level - imgrequest.m_requestedDiscardLevel = newRequest.DiscardLevel; + imgrequest.DiscardLevel = newRequest.DiscardLevel; //Update the requested packet number - imgrequest.m_requestedPacketNumber = newRequest.PacketNumber; + imgrequest.StartPacket = newRequest.PacketNumber; //Update the requested priority - imgrequest.m_requestedPriority = newRequest.Priority; + imgrequest.Priority = newRequest.Priority; try { lock (m_priorityQueue) - m_priorityQueue.Replace(imgrequest.m_priorityQueueHandle, imgrequest); + m_priorityQueue.Replace(imgrequest.PriorityQueueHandle, imgrequest); } catch (Exception) { - imgrequest.m_priorityQueueHandle = null; + imgrequest.PriorityQueueHandle = null; lock (m_priorityQueue) - m_priorityQueue.Add(ref imgrequest.m_priorityQueueHandle, imgrequest); + m_priorityQueue.Add(ref imgrequest.PriorityQueueHandle, imgrequest); } //Run an update @@ -161,29 +161,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP imgrequest = new J2KImage(this); //Assign our decoder module - imgrequest.m_j2kDecodeModule = m_j2kDecodeModule; + imgrequest.J2KDecoder = m_j2kDecodeModule; //Assign our asset cache module - imgrequest.m_assetCache = m_assetCache; + imgrequest.AssetService = m_assetCache; //Assign the requested discard level - imgrequest.m_requestedDiscardLevel = newRequest.DiscardLevel; + imgrequest.DiscardLevel = newRequest.DiscardLevel; //Assign the requested packet number - imgrequest.m_requestedPacketNumber = newRequest.PacketNumber; + imgrequest.StartPacket = newRequest.PacketNumber; //Assign the requested priority - imgrequest.m_requestedPriority = newRequest.Priority; + imgrequest.Priority = newRequest.Priority; //Assign the asset uuid - imgrequest.m_requestedUUID = newRequest.RequestedAssetID; + imgrequest.TextureID = newRequest.RequestedAssetID; //Assign the requested priority - imgrequest.m_requestedPriority = newRequest.Priority; + imgrequest.Priority = newRequest.Priority; //Add this download to the priority queue lock (m_priorityQueue) - m_priorityQueue.Add(ref imgrequest.m_priorityQueueHandle, imgrequest); + m_priorityQueue.Add(ref imgrequest.PriorityQueueHandle, imgrequest); //Run an update imgrequest.RunUpdate(); @@ -249,12 +249,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP lock (m_priorityQueue) imagereq = m_priorityQueue.FindMax(); - if (imagereq.m_decoded == true) + if (imagereq.IsDecoded == true) { // we need to test this here now that we are dropping assets - if (!imagereq.m_hasasset) + if (!imagereq.HasAsset) { - m_log.WarnFormat("[LLIMAGE MANAGER]: Re-requesting the image asset {0}", imagereq.m_requestedUUID); + m_log.WarnFormat("[LLIMAGE MANAGER]: Re-requesting the image asset {0}", imagereq.TextureID); imagereq.RunUpdate(); continue; } @@ -268,7 +268,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP try { lock (m_priorityQueue) - m_priorityQueue.Delete(imagereq.m_priorityQueueHandle); + m_priorityQueue.Delete(imagereq.PriorityQueueHandle); } catch (Exception) { } } -- cgit v1.1 From 332d3eb1bb4aecf67d56e64686db3e3851b848ea Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 2 Oct 2009 16:53:35 -0700 Subject: * Removed code that is no longer used with Melanie's queue callback optimization * Moved all priority queue access to helper functions to improve reliability and readability * New version of CSJ2K.dll (from libomv source tree) that fixes a JPEG2000 comment decoding bug --- .../Region/ClientStack/LindenUDP/LLImageManager.cs | 214 +++++++++------------ 1 file changed, 88 insertions(+), 126 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs index d641b6c..facfb9d 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs @@ -50,43 +50,38 @@ namespace OpenSim.Region.ClientStack.LindenUDP } private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private bool m_shuttingdown = false; - private long m_lastloopprocessed = 0; - private AssetBase m_missingImage = null; - + private bool m_shuttingdown; + private long m_lastloopprocessed; + private AssetBase m_missingImage; private LLClientView m_client; //Client we're assigned to private IAssetService m_assetCache; //Asset Cache private IJ2KDecoder m_j2kDecodeModule; //Our J2K module private C5.IntervalHeap m_priorityQueue = new C5.IntervalHeap(10, new J2KImageComparer()); + private object m_syncRoot = new object(); + + public LLClientView Client { get { return m_client; } } + public AssetBase MissingImage { get { return m_missingImage; } } public LLImageManager(LLClientView client, IAssetService pAssetCache, IJ2KDecoder pJ2kDecodeModule) { m_client = client; m_assetCache = pAssetCache; + if (pAssetCache != null) m_missingImage = pAssetCache.Get("5748decc-f629-461c-9a36-a35a221fe21f"); - else - m_log.Error("[ClientView] - couldn't set missing image asset, falling back to missing image packet. This is known to crash the client"); + + if (m_missingImage == null) + m_log.Error("[ClientView] - Couldn't set missing image asset, falling back to missing image packet. This is known to crash the client"); m_j2kDecodeModule = pJ2kDecodeModule; } - public LLClientView Client - { - get { return m_client; } - } - - public AssetBase MissingImage - { - get { return m_missingImage; } - } - + /// + /// Handles an incoming texture request or update to an existing texture request + /// + /// public void EnqueueReq(TextureRequestArgs newRequest) { - //newRequest is the properties of our new texture fetch request. - //Basically, here is where we queue up "new" requests.. - // .. or modify existing requests to suit. - //Make sure we're not shutting down.. if (!m_shuttingdown) { @@ -125,21 +120,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP imgrequest.DiscardLevel = newRequest.DiscardLevel; //Update the requested packet number - imgrequest.StartPacket = newRequest.PacketNumber; + imgrequest.StartPacket = Math.Max(1, newRequest.PacketNumber); //Update the requested priority imgrequest.Priority = newRequest.Priority; - try - { - lock (m_priorityQueue) - m_priorityQueue.Replace(imgrequest.PriorityQueueHandle, imgrequest); - } - catch (Exception) - { - imgrequest.PriorityQueueHandle = null; - lock (m_priorityQueue) - m_priorityQueue.Add(ref imgrequest.PriorityQueueHandle, imgrequest); - } + UpdateImageInQueue(imgrequest); //Run an update imgrequest.RunUpdate(); @@ -159,31 +144,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP // newRequest.RequestedAssetID, newRequest.DiscardLevel, newRequest.PacketNumber, newRequest.Priority); imgrequest = new J2KImage(this); - - //Assign our decoder module imgrequest.J2KDecoder = m_j2kDecodeModule; - - //Assign our asset cache module imgrequest.AssetService = m_assetCache; - - //Assign the requested discard level imgrequest.DiscardLevel = newRequest.DiscardLevel; - - //Assign the requested packet number - imgrequest.StartPacket = newRequest.PacketNumber; - - //Assign the requested priority + imgrequest.StartPacket = Math.Max(1, newRequest.PacketNumber); imgrequest.Priority = newRequest.Priority; - - //Assign the asset uuid imgrequest.TextureID = newRequest.RequestedAssetID; - - //Assign the requested priority imgrequest.Priority = newRequest.Priority; //Add this download to the priority queue - lock (m_priorityQueue) - m_priorityQueue.Add(ref imgrequest.PriorityQueueHandle, imgrequest); + AddImageToQueue(imgrequest); //Run an update imgrequest.RunUpdate(); @@ -194,105 +164,97 @@ namespace OpenSim.Region.ClientStack.LindenUDP public bool ProcessImageQueue(int count, int maxpack) { - lock (this) + J2KImage imagereq; + int numCollected = 0; + + lock (m_syncRoot) { - //count is the number of textures we want to process in one go. - //As part of this class re-write, that number will probably rise - //since we're processing in a more efficient manner. + m_lastloopprocessed = DateTime.Now.Ticks; - // this can happen during Close() - if (m_client == null) + // This can happen during Close() + if (m_client == null || m_client.PacketHandler == null || m_client.PacketHandler.PacketQueue == null) return false; - - int numCollected = 0; - - //Calculate our threshold - int threshold; - if (m_lastloopprocessed == 0) - { - if (m_client.PacketHandler == null || m_client.PacketHandler.PacketQueue == null || m_client.PacketHandler.PacketQueue.TextureThrottle == null) - return false; - //This is decent for a semi fast machine, but we'll calculate it more accurately based on time below - threshold = m_client.PacketHandler.PacketQueue.TextureThrottle.Current / 6300; - m_lastloopprocessed = DateTime.Now.Ticks; - } - else + + while ((imagereq = GetHighestPriorityImage()) != null) { - double throttleseconds = ((double)DateTime.Now.Ticks - (double)m_lastloopprocessed) / (double)TimeSpan.TicksPerSecond; - throttleseconds = throttleseconds * m_client.PacketHandler.PacketQueue.TextureThrottle.Current; - - //Average of 1000 bytes per packet - throttleseconds = throttleseconds / 1000; - - //Safe-zone multiplier of 2.0 - threshold = (int)(throttleseconds * 2.0); - m_lastloopprocessed = DateTime.Now.Ticks; - - } - - if (m_client.PacketHandler == null) - return false; - - if (m_client.PacketHandler.PacketQueue == null) - return false; - - if (threshold < 10) - threshold = 10; - - //Uncomment this to see what the texture stack is doing - //m_log.Debug("Queue: " + m_client.PacketHandler.PacketQueue.getQueueCount(ThrottleOutPacketType.Texture).ToString() + " Threshold: " + threshold.ToString() + " outstanding: " + m_outstandingtextures.ToString()); - if (true) //m_client.PacketHandler.PacketQueue.GetQueueCount(ThrottleOutPacketType.Texture) < threshold) - { - while (m_priorityQueue.Count > 0) + if (imagereq.IsDecoded == true) { - J2KImage imagereq = null; - lock (m_priorityQueue) - imagereq = m_priorityQueue.FindMax(); + ++numCollected; - if (imagereq.IsDecoded == true) + if (imagereq.SendPackets(m_client, maxpack)) { - // we need to test this here now that we are dropping assets - if (!imagereq.HasAsset) - { - m_log.WarnFormat("[LLIMAGE MANAGER]: Re-requesting the image asset {0}", imagereq.TextureID); - imagereq.RunUpdate(); - continue; - } - - ++numCollected; - - //SendPackets will send up to ten packets per cycle - if (imagereq.SendPackets(m_client, maxpack)) - { - // Send complete. Destroy any knowledge of this transfer - try - { - lock (m_priorityQueue) - m_priorityQueue.Delete(imagereq.PriorityQueueHandle); - } - catch (Exception) { } - } + // Send complete. Destroy any knowledge of this transfer + RemoveImageFromQueue(imagereq); } - - if (numCollected == count) - break; } - } - return m_priorityQueue.Count > 0; + if (numCollected == count) + break; + } } + + return m_priorityQueue.Count > 0; } //Faux destructor public void Close() { - m_shuttingdown = true; m_j2kDecodeModule = null; m_assetCache = null; m_client = null; } + #region Priority Queue Helpers + + J2KImage GetHighestPriorityImage() + { + J2KImage image = null; + + if (m_priorityQueue.Count > 0) + { + try + { + lock (m_priorityQueue) + image = m_priorityQueue.FindMax(); + } + catch (Exception) { } + } + + return image; + } + + void AddImageToQueue(J2KImage image) + { + image.PriorityQueueHandle = null; + + lock (m_priorityQueue) + m_priorityQueue.Add(ref image.PriorityQueueHandle, image); + } + + void RemoveImageFromQueue(J2KImage image) + { + try + { + lock (m_priorityQueue) + m_priorityQueue.Delete(image.PriorityQueueHandle); + } + catch (Exception) { } + } + + void UpdateImageInQueue(J2KImage image) + { + lock (m_priorityQueue) + { + try { m_priorityQueue.Replace(image.PriorityQueueHandle, image); } + catch (Exception) + { + image.PriorityQueueHandle = null; + m_priorityQueue.Add(ref image.PriorityQueueHandle, image); + } + } + } + #endregion Priority Queue Helpers } } -- cgit v1.1 From 387e9f7a7faeb412054383080afc3507a1522746 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 2 Oct 2009 18:31:08 -0700 Subject: * Creates Util.UTF8 and switches some references of Encoding.UTF8 to Util.UTF8 (not all references were switched since not all OpenSim libraries reference OpenSim.Framework) * Shrinks the largest in-memory object, the LLRAW.HeightmapLookupValue struct (only used for exporting to LLRAW terrain files), to the minimum possible size. This seems to have the odd side effect of cutting the size of the two double[256,256] terrain objects in half. Possibly an alignment optimization? --- OpenSim/Region/Application/OpenSimBase.cs | 6 +++--- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 4 ++-- .../Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs | 4 ++-- .../CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | 4 ++-- OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs | 10 +++++----- OpenSim/Region/DataSnapshot/DataSnapshotManager.cs | 2 +- OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs | 2 +- OpenSim/Region/Framework/Scenes/TerrainChannel.cs | 2 +- .../Agent/InternetRelayClientView/Server/IRCClientView.cs | 4 ++-- .../Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs | 4 ++-- .../OptionalModules/World/TreePopulator/TreePopulatorModule.cs | 2 +- .../Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 2 +- .../Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 2 +- 13 files changed, 24 insertions(+), 24 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 7bc0b77..6b6cb85 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -699,7 +699,7 @@ namespace OpenSim public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { - return Encoding.UTF8.GetBytes("OK"); + return Util.UTF8.GetBytes("OK"); } public string ContentType @@ -736,7 +736,7 @@ namespace OpenSim public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { - return Encoding.UTF8.GetBytes(m_opensim.StatReport(httpRequest)); + return Util.UTF8.GetBytes(m_opensim.StatReport(httpRequest)); } public string ContentType @@ -777,7 +777,7 @@ namespace OpenSim public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { - return Encoding.UTF8.GetBytes(m_opensim.StatReport(httpRequest)); + return Util.UTF8.GetBytes(m_opensim.StatReport(httpRequest)); } public string ContentType diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 43d29fd..3f90004 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -4748,7 +4748,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP { Hashtable mp = (Hashtable)simMapProfiles[iii]; mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock(); - mbReply.Data[iii].Name = System.Text.Encoding.UTF8.GetBytes((string)mp["name"]); + mbReply.Data[iii].Name = Util.UTF8.GetBytes((string)mp["name"]); mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]); mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]); mbReply.Data[iii].MapImageID = new UUID((string)mp["map-image-id"]); @@ -7338,7 +7338,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP } #endregion - string mapName = Encoding.UTF8.GetString(map.NameData.Name, 0, + string mapName = Util.UTF8.GetString(map.NameData.Name, 0, map.NameData.Name.Length - 1); handlerMapNameRequest = OnMapNameRequest; if (handlerMapNameRequest != null) diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs index a0f359b..7456e8c 100644 --- a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs +++ b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs @@ -257,7 +257,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender stringResult.AppendFormat("{0}|{1}|{2}{3}", Layers[i].Start, Layers[i].End, Layers[i].End - Layers[i].Start, strEnd); } - layerDecodeAsset.Data = Encoding.UTF8.GetBytes(stringResult.ToString()); + layerDecodeAsset.Data = Util.UTF8.GetBytes(stringResult.ToString()); #endregion Serialize Layer Data @@ -280,7 +280,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender { #region Deserialize Layer Data - string readResult = Encoding.UTF8.GetString(layerDecodeAsset.Data); + string readResult = Util.UTF8.GetString(layerDecodeAsset.Data); string[] lines = readResult.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); if (lines.Length == 0) diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index 50d7c97..45e724d 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs @@ -367,7 +367,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest // Encode outbound data if (OutboundBody.Length > 0) { - byte[] data = Encoding.UTF8.GetBytes(OutboundBody); + byte[] data = Util.UTF8.GetBytes(OutboundBody); Request.ContentLength = data.Length; Stream bstream = Request.GetRequestStream(); @@ -390,7 +390,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest if (count != 0) { // translate from bytes to ASCII text - tempString = Encoding.UTF8.GetString(buf, 0, count); + tempString = Util.UTF8.GetString(buf, 0, count); // continue building the string sb.Append(tempString); diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs index 3eb7cd2..a70ef13 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs @@ -36,10 +36,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders { public struct HeightmapLookupValue : IComparable { - public int Index; - public double Value; + public ushort Index; + public float Value; - public HeightmapLookupValue(int index, double value) + public HeightmapLookupValue(ushort index, float value) { Index = index; Value = value; @@ -62,7 +62,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders { for (int j = 0; j < 256; j++) { - LookupHeightTable[i + (j * 256)] = new HeightmapLookupValue(i + (j * 256), ((double)i * ((double)j / 128.0d))); + LookupHeightTable[i + (j * 256)] = new HeightmapLookupValue((ushort)(i + (j * 256)), (float)((double)i * ((double)j / 128.0d))); } } Array.Sort(LookupHeightTable); @@ -196,7 +196,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders // The lookup table is pre-sorted, so we either find an exact match or // the next closest (smaller) match with a binary search - index = Array.BinarySearch(LookupHeightTable, new HeightmapLookupValue(0, t)); + index = Array.BinarySearch(LookupHeightTable, new HeightmapLookupValue(0, (float)t)); if (index < 0) index = ~index - 1; diff --git a/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs b/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs index 080bd5a..4df9094 100644 --- a/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs +++ b/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs @@ -352,7 +352,7 @@ namespace OpenSim.Region.DataSnapshot m_log.WarnFormat("[DATASNAPSHOT]: Unable to decode reply from data service. Ignoring. {0}", e.StackTrace); } // This is not quite working, so... - // string responseStr = Encoding.UTF8.GetString(response); + // string responseStr = Util.UTF8.GetString(response); m_log.Info("[DATASNAPSHOT]: data service notified: " + url); } diff --git a/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs b/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs index 7c02f9a..6055384 100644 --- a/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs +++ b/OpenSim/Region/Framework/Scenes/RegionStatsHandler.cs @@ -73,7 +73,7 @@ namespace OpenSim.Region.Framework.Scenes public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { - return Encoding.UTF8.GetBytes(Report()); + return Util.UTF8.GetBytes(Report()); } public string ContentType diff --git a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs index 8209ff6..ca6210d 100644 --- a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs +++ b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs @@ -172,7 +172,7 @@ namespace OpenSim.Region.Framework.Scenes public string SaveToXmlString() { XmlWriterSettings settings = new XmlWriterSettings(); - settings.Encoding = Encoding.UTF8; + settings.Encoding = Util.UTF8; using (StringWriter sw = new StringWriter()) { using (XmlWriter writer = XmlWriter.Create(sw, settings)) diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs index 57f5d29..a31cbae 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs @@ -81,7 +81,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server { m_log.Info("[IRCd] Sending >>> " + command); - byte[] buf = Encoding.UTF8.GetBytes(command + "\r\n"); + byte[] buf = Util.UTF8.GetBytes(command + "\r\n"); m_client.GetStream().BeginWrite(buf, 0, buf.Length, SendComplete, null); } @@ -109,7 +109,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server byte[] buf = new byte[8]; // RFC1459 defines max message size as 512. int count = m_client.GetStream().Read(buf, 0, buf.Length); - string line = Encoding.UTF8.GetString(buf, 0, count); + string line = Util.UTF8.GetString(buf, 0, count); strbuf += line; diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs index 65c5274..f9dfc0d 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs @@ -527,7 +527,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice if (method == "POST") { - byte[] contentreq = Encoding.UTF8.GetBytes(body); + byte[] contentreq = Util.UTF8.GetBytes(body); forwardreq.ContentLength = contentreq.Length; Stream reqStream = forwardreq.GetRequestStream(); reqStream.Write(contentreq, 0, contentreq.Length); @@ -535,7 +535,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice } HttpWebResponse fwdrsp = (HttpWebResponse)forwardreq.GetResponse(); - Encoding encoding = Encoding.UTF8; + Encoding encoding = Util.UTF8; StreamReader fwdresponsestream = new StreamReader(fwdrsp.GetResponseStream(), encoding); fwdresponsestr = fwdresponsestream.ReadToEnd(); fwdresponsecontenttype = fwdrsp.ContentType; diff --git a/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs b/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs index d4bba10..b6021a9 100644 --- a/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs +++ b/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs @@ -539,7 +539,7 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator { XmlSerializer xs = new XmlSerializer(typeof(Copse)); - using (XmlTextWriter writer = new XmlTextWriter(fileName, System.Text.Encoding.UTF8)) + using (XmlTextWriter writer = new XmlTextWriter(fileName, Util.UTF8)) { writer.Formatting = Formatting.Indented; xs.Serialize(writer, obj); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index ba42678..264d585 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -7064,7 +7064,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api try { byte[] encData_byte = new byte[str.Length]; - encData_byte = Encoding.UTF8.GetBytes(str); + encData_byte = Util.UTF8.GetBytes(str); string encodedData = Convert.ToBase64String(encData_byte); return encodedData; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 726b37a..f80dd51 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -1457,7 +1457,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " + textLength.ToString() + "\n" + notecardData + "}\n"; - asset.Data = Encoding.UTF8.GetBytes(notecardData); + asset.Data = Util.UTF8.GetBytes(notecardData); World.AssetService.Store(asset); // Create Task Entry -- cgit v1.1 From b4d1cf0009777fa95760419c955eb20e1027badf Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 3 Oct 2009 14:22:29 +0100 Subject: Small permissions tweak --- OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs index 040d0a3..89d74b5 100644 --- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs +++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs @@ -576,9 +576,12 @@ namespace OpenSim.Region.CoreModules.World.Permissions return objectOwnerMask; } + if ((objectOwnerMask & PermissionMask.Transfer != 0) && task.saleType != 0) + objectEveryoneMask |= ObjectFlags.ObjectTransfer; + // Group permissions if ((task.GroupID != UUID.Zero) && IsGroupMember(task.GroupID, user, 0)) - return objectGroupMask; + return objectGroupMask | objectEveryoneMask; return objectEveryoneMask; } -- cgit v1.1 From 874e4231413b27f3f2eed67adca382b1918963cc Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 3 Oct 2009 15:37:31 +0100 Subject: Fix my build break --- OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs index 89d74b5..9622555 100644 --- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs +++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs @@ -576,8 +576,8 @@ namespace OpenSim.Region.CoreModules.World.Permissions return objectOwnerMask; } - if ((objectOwnerMask & PermissionMask.Transfer != 0) && task.saleType != 0) - objectEveryoneMask |= ObjectFlags.ObjectTransfer; + if ((objectOwnerMask & (uint)PermissionMask.Transfer) != 0 && task.ObjectSaleType != 0) + objectEveryoneMask |= (uint)PrimFlags.ObjectTransfer; // Group permissions if ((task.GroupID != UUID.Zero) && IsGroupMember(task.GroupID, user, 0)) -- cgit v1.1 From 0cbd9eee2f1ed501bb2bc912c560934feb3edb26 Mon Sep 17 00:00:00 2001 From: dahlia Date: Sun, 4 Oct 2009 02:14:13 -0700 Subject: Exclude sculpt proxies from mesh caching --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 29 +++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index d56ddc8..ea6e10b 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -224,6 +224,14 @@ namespace OpenSim.Region.Physics.Meshing for (int i = 0; i < lodBytes.Length; i++) hash = djb2(hash, lodBytes[i]); + // include sculpt UUID + if (pbs.SculptEntry) + { + scaleBytes = pbs.SculptTexture.GetBytes(); + for (int i = 0; i < scaleBytes.Length; i++) + hash = djb2(hash, scaleBytes[i]); + } + return hash; } @@ -330,7 +338,7 @@ namespace OpenSim.Region.Physics.Meshing bool invert = ((primShape.SculptType & 64) != 0); sculptMesh = new PrimMesher.SculptMesh((Bitmap)idata, sculptType, (int)lod, false, mirror, invert); - + idata.Dispose(); sculptMesh.DumpRaw(baseDir, primName, "primMesh"); @@ -484,12 +492,18 @@ namespace OpenSim.Region.Physics.Meshing public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod, bool isPhysical) { + Mesh mesh = null; + ulong key = 0; + // If this mesh has been created already, return it instead of creating another copy // For large regions with 100k+ prims and hundreds of copies of each, this can save a GB or more of memory - ulong key = GetMeshKey(primShape, size, lod); - Mesh mesh = null; - if (m_uniqueMeshes.TryGetValue(key, out mesh)) - return mesh; + + if (! primShape.SculptEntry) + { + key = GetMeshKey(primShape, size, lod); + if (m_uniqueMeshes.TryGetValue(key, out mesh)) + return mesh; + } if (size.X < 0.01f) size.X = 0.01f; if (size.Y < 0.01f) size.Y = 0.01f; @@ -512,7 +526,10 @@ namespace OpenSim.Region.Physics.Meshing // trim the vertex and triangle lists to free up memory mesh.TrimExcess(); } - m_uniqueMeshes.Add(key, mesh); + + if (!primShape.SculptEntry) + m_uniqueMeshes.Add(key, mesh); + return mesh; } } -- cgit v1.1 From efebc809ce1ecbce0e3619af5439805f91e14870 Mon Sep 17 00:00:00 2001 From: dahlia Date: Sun, 4 Oct 2009 02:54:36 -0700 Subject: disable physics actors for flexible prims --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index ea6bc9c..801a7db 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1344,7 +1344,8 @@ if (m_shape != null) { bool RigidBody = isPhysical && !isPhantom; // The only time the physics scene shouldn't know about the prim is if it's phantom or an attachment, which is phantom by definition - if (!isPhantom && !IsAttachment) + // or flexible + if (!isPhantom && !IsAttachment && !(Shape.PathCurve == (byte) Extrusion.Flexible)) { PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape( Name, @@ -3426,8 +3427,8 @@ if (m_shape != null) { } } - - if (IsPhantom || IsAttachment) // note: this may have been changed above in the case of joints + + if (IsPhantom || IsAttachment || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints { AddFlag(PrimFlags.Phantom); PhysicsActor pa = PhysActor; -- cgit v1.1 From 95ebb7794cd016485f3ce4e4449091955a6e9eaf Mon Sep 17 00:00:00 2001 From: dahlia Date: Sun, 4 Oct 2009 02:59:12 -0700 Subject: flexible extrusion shape defaults to linear --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index ea6e10b..0e29ccc 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -397,7 +397,7 @@ namespace OpenSim.Region.Physics.Meshing primMesh.pathCutBegin = pathBegin; primMesh.pathCutEnd = pathEnd; - if (primShape.PathCurve == (byte)Extrusion.Straight) + if (primShape.PathCurve == (byte)Extrusion.Straight || primShape.PathCurve == (byte) Extrusion.Flexible) { primMesh.twistBegin = primShape.PathTwistBegin * 18 / 10; primMesh.twistEnd = primShape.PathTwist * 18 / 10; -- cgit v1.1 From 366bfe17ae46ddfe7b942b5851a1625072b4852b Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 4 Oct 2009 07:41:10 -0700 Subject: Trying to avoid the null pointer exception in J2KImage, RunUpdate. --- OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs b/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs index 0e3630c..713d43a 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs @@ -158,9 +158,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP m_currentPacket = m_stopPacket; return; } - + if (DiscardLevel >= 0 || m_stopPacket == 0) { + // This shouldn't happen, but if it does, we really can't proceed + if (Layers == null) + { + m_log.Warn("[J2KIMAGE]: RunUpdate() called with missing Layers. Canceling texture transfer"); + m_currentPacket = m_stopPacket; + return; + } + int maxDiscardLevel = Math.Max(0, Layers.Length - 1); // Treat initial texture downloads with a DiscardLevel of -1 a request for the highest DiscardLevel -- cgit v1.1 From b803d5ab9b6aae1316314efcbbb80e3f1ab6322a Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 4 Oct 2009 09:44:04 -0700 Subject: Make sure to close the file streams on the FlotsamCache, even if something fails. --- OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index 817e0d4..1dc40bc 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -323,13 +323,13 @@ namespace Flotsam.RegionModules.AssetCache string filename = GetFileName(id); if (File.Exists(filename)) { + FileStream stream = null; try { - FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read); + stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryFormatter bformatter = new BinaryFormatter(); asset = (AssetBase)bformatter.Deserialize(stream); - stream.Close(); UpdateMemoryCache(id, asset); @@ -349,6 +349,11 @@ namespace Flotsam.RegionModules.AssetCache { LogException(e); } + finally + { + if (stream != null) + stream.Close(); + } } @@ -493,6 +498,7 @@ namespace Flotsam.RegionModules.AssetCache private void WriteFileCache(string filename, AssetBase asset) { + Stream stream = null; try { // Make sure the target cache directory exists @@ -505,10 +511,9 @@ namespace Flotsam.RegionModules.AssetCache // Write file first to a temp name, so that it doesn't look // like it's already cached while it's still writing. string tempname = Path.Combine(directory, Path.GetRandomFileName()); - Stream stream = File.Open(tempname, FileMode.Create); + stream = File.Open(tempname, FileMode.Create); BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, asset); - stream.Close(); // Now that it's written, rename it so that it can be found. File.Move(tempname, filename); @@ -522,6 +527,9 @@ namespace Flotsam.RegionModules.AssetCache } finally { + if (stream != null) + stream.Close(); + // Even if the write fails with an exception, we need to make sure // that we release the lock on that file, otherwise it'll never get // cached -- cgit v1.1 From fe9cca64dea714583c09854a90f2c13fecb12d29 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 4 Oct 2009 09:56:54 -0700 Subject: Stream needs to be closed before the file can be moved... --- OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index 1dc40bc..c0bb70c 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -499,21 +499,22 @@ namespace Flotsam.RegionModules.AssetCache private void WriteFileCache(string filename, AssetBase asset) { Stream stream = null; + // Make sure the target cache directory exists + string directory = Path.GetDirectoryName(filename); + // Write file first to a temp name, so that it doesn't look + // like it's already cached while it's still writing. + string tempname = Path.Combine(directory, Path.GetRandomFileName()); try { - // Make sure the target cache directory exists - string directory = Path.GetDirectoryName(filename); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } - // Write file first to a temp name, so that it doesn't look - // like it's already cached while it's still writing. - string tempname = Path.Combine(directory, Path.GetRandomFileName()); stream = File.Open(tempname, FileMode.Create); BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, asset); + stream.Close(); // Now that it's written, rename it so that it can be found. File.Move(tempname, filename); -- cgit v1.1 From d93e0a05037495dcdabdffcc9b9f78747271da39 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 4 Oct 2009 10:30:21 -0700 Subject: Guarding a line that is sometimes throwing a null pointer exception. --- OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs b/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs index 713d43a..19ad0b4 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs @@ -197,11 +197,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP m_currentPacket = StartPacket; } - if (m_imageManager.Client.PacketHandler.GetQueueCount(ThrottleOutPacketType.Texture) == 0) - { - //m_log.Debug("No textures queued, sending one packet to kickstart it"); - SendPacket(m_imageManager.Client); - } + if ((m_imageManager != null) && (m_imageManager.Client != null) && (m_imageManager.Client.PacketHandler != null)) + if (m_imageManager.Client.PacketHandler.GetQueueCount(ThrottleOutPacketType.Texture) == 0) + { + //m_log.Debug("No textures queued, sending one packet to kickstart it"); + SendPacket(m_imageManager.Client); + } } } } -- cgit v1.1 From 29a4614529bbda02b9c690d2d1812be1d1e7bbae Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Sun, 4 Oct 2009 13:57:51 -0700 Subject: * MySQL data tests now pass by fixing a bad fix for a bad cast on the asset Local member in MySQLAssetData * First pass at applying the using(){} pattern to IDisposable objects. Always use the using pattern on IDisposable objects whenever possible, do not manually call .Close() or .Dispose() unless there is no other way to write the code. This pass mostly covers OpenSim.Data.MySQL, and should have no functional change (tests still pass) --- OpenSim/Region/Application/Application.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Application/Application.cs b/OpenSim/Region/Application/Application.cs index 241af53..33b01e5 100644 --- a/OpenSim/Region/Application/Application.cs +++ b/OpenSim/Region/Application/Application.cs @@ -205,13 +205,10 @@ namespace OpenSim Directory.CreateDirectory(m_crashDir); } string log = Util.GetUniqueFilename(ex.GetType() + ".txt"); - StreamWriter m_crashLog = - new StreamWriter( - Path.Combine(m_crashDir, log) - ); - - m_crashLog.WriteLine(msg); - m_crashLog.Close(); + using (StreamWriter m_crashLog = new StreamWriter(Path.Combine(m_crashDir, log))) + { + m_crashLog.WriteLine(msg); + } File.Copy("OpenSim.ini", Path.Combine(m_crashDir, log + "_OpenSim.ini"), true); } -- cgit v1.1 From 5b19d5a7b763a5ff5a7380f00c08fc30f4707588 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 4 Oct 2009 14:05:58 -0700 Subject: Reduced locking. --- OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs index facfb9d..2120d33 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs @@ -167,8 +167,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP J2KImage imagereq; int numCollected = 0; - lock (m_syncRoot) - { + //lock (m_syncRoot) + //{ m_lastloopprocessed = DateTime.Now.Ticks; // This can happen during Close() @@ -191,7 +191,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (numCollected == count) break; } - } + //} return m_priorityQueue.Count > 0; } @@ -211,16 +211,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP { J2KImage image = null; - if (m_priorityQueue.Count > 0) + lock (m_priorityQueue) { - try + + if (m_priorityQueue.Count > 0) { - lock (m_priorityQueue) + try + { image = m_priorityQueue.FindMax(); + } + catch (Exception) { } } - catch (Exception) { } } - return image; } -- cgit v1.1 From 362e94a0229d0b450001b8b089a472b550b530f3 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 4 Oct 2009 16:30:12 -0700 Subject: * KeepAlive set to false in expect_user and log_off. * Check for null SP in PermissionsModule. --- .../CoreModules/World/Permissions/PermissionsModule.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs index 9622555..901144a 100644 --- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs +++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs @@ -397,10 +397,15 @@ namespace OpenSim.Region.CoreModules.World.Permissions // with the powers requested (powers = 0 for no powers check) protected bool IsGroupMember(UUID groupID, UUID userID, ulong powers) { - IClientAPI client = m_scene.GetScenePresence(userID).ControllingClient; - - return ((groupID == client.ActiveGroupId) && (client.ActiveGroupPowers != 0) && - ((powers == 0) || ((client.ActiveGroupPowers & powers) == powers))); + ScenePresence sp = m_scene.GetScenePresence(userID); + if (sp != null) + { + IClientAPI client = sp.ControllingClient; + + return ((groupID == client.ActiveGroupId) && (client.ActiveGroupPowers != 0) && + ((powers == 0) || ((client.ActiveGroupPowers & powers) == powers))); + } + return false; } /// -- cgit v1.1