diff --git a/Source/Core/Data/DataManager.cs b/Source/Core/Data/DataManager.cs index c68607e2..c5cf72d0 100644 --- a/Source/Core/Data/DataManager.cs +++ b/Source/Core/Data/DataManager.cs @@ -566,7 +566,7 @@ namespace CodeImp.DoomBuilder.Data } // Unload this image? - if(!image.IsReferenced && (image.ImageState != ImageLoadState.None)) + if(!image.IsReferenced && image.AllowUnload && (image.ImageState != ImageLoadState.None)) { // Still unreferenced? image.UnloadImage(); @@ -639,7 +639,7 @@ namespace CodeImp.DoomBuilder.Data } // Unload this image? - if((img.ImageState == ImageLoadState.Ready) && !img.IsReferenced) + if((img.ImageState == ImageLoadState.Ready) && !img.IsReferenced && img.AllowUnload) { // Add for unloading img.ImageState = ImageLoadState.Unloading; @@ -1087,6 +1087,7 @@ namespace CodeImp.DoomBuilder.Data { ImageData img = new FileImage(Path.GetFileNameWithoutExtension(spritefile).ToLowerInvariant(), spritefile, false); img.LoadImage(); + img.AllowUnload = false; internalsprites.Add(img.Name, img); } @@ -1095,6 +1096,7 @@ namespace CodeImp.DoomBuilder.Data { ImageData img = new ResourceImage("CodeImp.DoomBuilder.Resources.Nothing.png"); img.LoadImage(); + img.AllowUnload = false; internalsprites.Add("nothing", img); } @@ -1102,6 +1104,7 @@ namespace CodeImp.DoomBuilder.Data { ImageData img = new ResourceImage("CodeImp.DoomBuilder.Resources.UnknownThing.png"); img.LoadImage(); + img.AllowUnload = false; internalsprites.Add("unknownthing", img); } } diff --git a/Source/Core/Data/ImageData.cs b/Source/Core/Data/ImageData.cs index 94db9aca..a3cb00e6 100644 --- a/Source/Core/Data/ImageData.cs +++ b/Source/Core/Data/ImageData.cs @@ -59,6 +59,7 @@ namespace CodeImp.DoomBuilder.Data private volatile ImageLoadState imagestate; private volatile int previewindex; protected volatile bool loadfailed; + private volatile bool allowunload; // References private volatile bool usedinmap; @@ -86,6 +87,7 @@ namespace CodeImp.DoomBuilder.Data public bool IsImageLoaded { get { return (imagestate == ImageLoadState.Ready); } } public bool LoadFailed { get { return loadfailed; } } public bool IsDisposed { get { return isdisposed; } } + public bool AllowUnload { get { return allowunload; } set { allowunload = value; } } public ImageLoadState ImageState { get { return imagestate; } internal set { imagestate = value; } } public ImageLoadState PreviewState { get { return previewstate; } internal set { previewstate = value; } } public bool IsReferenced { get { return (references > 0) || usedinmap; } } @@ -108,6 +110,7 @@ namespace CodeImp.DoomBuilder.Data { // Defaults usecolorcorrection = true; + allowunload = true; } // Destructor diff --git a/Source/Core/Windows/ThingEditForm.cs b/Source/Core/Windows/ThingEditForm.cs index 984300b0..5e805bc0 100644 --- a/Source/Core/Windows/ThingEditForm.cs +++ b/Source/Core/Windows/ThingEditForm.cs @@ -185,12 +185,22 @@ namespace CodeImp.DoomBuilder.Windows // Selected type changes private void thingtype_OnTypeChanged(ThingTypeInfo value) { - // Update preview image thinginfo = value; - if(value != null) - General.DisplayZoomedImage(spritetex, General.Map.Data.GetSpriteImage(value.Sprite).GetPreview()); + + // Update preview image + if(thinginfo.Sprite.ToLowerInvariant().StartsWith(DataManager.INTERNAL_PREFIX) && + (thinginfo.Sprite.Length > DataManager.INTERNAL_PREFIX.Length)) + { + General.DisplayZoomedImage(spritetex, General.Map.Data.GetSpriteImage(thinginfo.Sprite).GetBitmap()); + } + else if((thinginfo.Sprite.Length <= 8) && (thinginfo.Sprite.Length > 0)) + { + General.DisplayZoomedImage(spritetex, General.Map.Data.GetSpriteImage(thinginfo.Sprite).GetPreview()); + } else - General.DisplayZoomedImage(spritetex, null); + { + spritetex.BackgroundImage = null; + } // Update arguments action_ValueChanges(this, EventArgs.Empty);