/// <summary>
        /// Creates an unscaled <see cref="Bitmap"/> of a <see cref="StationaryGrhData"/>.
        /// </summary>
        /// <param name="gd">The <see cref="StationaryGrhData"/>.</param>
        /// <returns>The unscaled <see cref="Bitmap"/>, or null if an error occured.</returns>
        static Bitmap CreateUnscaledBitmap(StationaryGrhData gd)
        {
            Bitmap img;

            // The image was null, so we are going to be the ones to create it
            try
            {
                // Try to create the image
                var tex = gd.GetOriginalTexture();
                if (tex == null)
                {
                    img = null;
                }
                else
                {
                    img = tex.ToBitmap(gd.OriginalSourceRect);
                }
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to create GrhImageList image for `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, gd, ex);
                }
                if (!(ex is LoadingFailedException))
                {
                    Debug.Fail(string.Format(errmsg, gd, ex));
                }
                img = null;
            }

            return(img);
        }
        /// <summary>
        /// Creates an <see cref="Image"/> for a <see cref="StationaryGrhData"/>, adds it to the cache, and returns it.
        /// Only call this if the image actually needs to be created, and never call this while in the <see cref="_imagesSync"/>
        /// lock!
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="gd">The <see cref="StationaryGrhData"/>.</param>
        /// <returns>The <see cref="Image"/>.</returns>
        Image CreateAndInsertImage(string key, StationaryGrhData gd)
        {
            Image img;

            // The image was null, so we are going to be the ones to create it
            try
            {
                // Try to create the image
                var tex = gd.GetOriginalTexture();
                if (tex == null)
                {
                    img = ErrorImage;
                }
                else
                {
                    img = tex.ToBitmap(gd.OriginalSourceRect, ImageWidth, ImageHeight);
                }
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to create GrhImageList image for `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, gd, ex);
                }
                if (!(ex is LoadingFailedException))
                {
                    Debug.Fail(string.Format(errmsg, gd, ex));
                }
                img = _errorImage;
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Created GrhImageList image for `{0}`.", img);
            }

            // If we for some reason have the _placeholder or null image by this point, there is an error in the logic above. But to
            // avoid a deadlock (even though this should never happen), we will just set it to the ErrorImage if it somehow does.
            if (img == null || img == _placeholder)
            {
                const string errmsg = "Created image was either null or the placeholder image, which should never happen.";
                if (log.IsErrorEnabled)
                {
                    log.Error(errmsg);
                }
                Debug.Fail(errmsg);
                img = _errorImage;
            }

            // Add the image to the cache (it will either be the correct image, or the ErrorImage if it failed). Remember that we
            // have already inserted the placeholder image at the key. So we're just replacing the placeholder with the actual image.
            lock (_imagesSync)
            {
                Debug.Assert(_images[key] == _placeholder);
                _images[key] = img;
            }

            // Return the generated image
            return(img);
        }