Visual mode: fixed a crash when trying to load non existing sprite, defined in configuration or via "//@sprite" parameter in DECORATE.

MissingThing icon is now used when the editor is unable to load thing sprite.
An error is added to error logger when the editor is unable to load thing sprite.
This commit is contained in:
MaxED 2013-08-21 10:45:54 +00:00
parent 2b14e5b8d0
commit 7ba352216d
8 changed files with 57 additions and 28 deletions

View file

@ -926,6 +926,7 @@
<None Include="Resources\MLogo.png" />
<None Include="Resources\Marine.png" />
<None Include="Resources\Link.png" />
<EmbeddedResource Include="Resources\MissingThing.png" />
<Content Include="Resources\Model.png" />
<Content Include="Resources\Model_selected.png" />
<EmbeddedResource Include="Resources\UDMF_UI.cfg" />

View file

@ -1060,7 +1060,7 @@ namespace CodeImp.DoomBuilder.Data
foreach(ThingTypeInfo ti in General.Map.Data.ThingTypes)
{
// Valid sprite name?
if((ti.Sprite.Length > 0) && (ti.Sprite.Length <= 8))
if((ti.Sprite.Length > 0) && (ti.Sprite.Length < 9))
{
ImageData image = null;
@ -1077,6 +1077,10 @@ namespace CodeImp.DoomBuilder.Data
// Add to collection
sprites.Add(ti.SpriteLongName, image);
}
else
{ //mxd
General.ErrorLogger.Add(ErrorType.Error, "Missing sprite lump '" + ti.Sprite + "'. Forgot to include required resources?");
}
}
else
{
@ -1160,10 +1164,20 @@ namespace CodeImp.DoomBuilder.Data
img.LoadImage();
img.AllowUnload = false;
internalsprites.Add("unknownthing", img);
previews.AddImage(img); //mxd
}
//mxd
if(!internalsprites.ContainsKey("missingthing")) {
ImageData img = new ResourceImage("CodeImp.DoomBuilder.Resources.MissingThing.png");
img.LoadImage();
img.AllowUnload = false;
internalsprites.Add("missingthing", img);
previews.AddImage(img);
}
}
// This returns an image by long
// This returns an image by name
public ImageData GetSpriteImage(string name)
{
// Is this referring to an internal sprite image?
@ -1172,13 +1186,9 @@ namespace CodeImp.DoomBuilder.Data
// Get the internal sprite
string internalname = name.Substring(INTERNAL_PREFIX.Length).ToLowerInvariant();
if(internalsprites.ContainsKey(internalname))
{
return internalsprites[internalname];
}
else
{
return unknownImage; //mxd
}
return internalsprites["unknownthing"]; //mxd
}
else
{
@ -1198,7 +1208,7 @@ namespace CodeImp.DoomBuilder.Data
// Go for all opened containers
for(int i = containers.Count - 1; i >= 0; i--)
{
// This contain provides this sprite?
// This container provides this sprite?
spritedata = containers[i].GetSpriteData(name);
if(spritedata != null) break;
}
@ -1215,10 +1225,15 @@ namespace CodeImp.DoomBuilder.Data
// Return result
return image;
}
else
else //mxd
{
ImageData img = string.IsNullOrEmpty(name) ? internalsprites["unknownthing"] : internalsprites["missingthing"];
// Add to collection
sprites.Add(longname, img);
// Return null image
return unknownImage; //mxd
return img;
}
}
}

View file

@ -134,11 +134,11 @@ namespace CodeImp.DoomBuilder.Data
}
// Determine preview size
float scalex = (img.Width > maxpreviewwidth) ? ((float)maxpreviewwidth / (float)imagewidth) : 1.0f;
float scaley = (img.Height > maxpreviewheight) ? ((float)maxpreviewheight / (float)imageheight) : 1.0f;
float scalex = (img.Width > maxpreviewwidth) ? (maxpreviewwidth / (float)imagewidth) : 1.0f;
float scaley = (img.Height > maxpreviewheight) ? (maxpreviewheight / (float)imageheight) : 1.0f;
float scale = Math.Min(scalex, scaley);
previewwidth = (int)((float)imagewidth * scale);
previewheight = (int)((float)imageheight * scale);
previewwidth = (int)(imagewidth * scale);
previewheight = (int)(imageheight * scale);
if(previewwidth < 1) previewwidth = 1;
if(previewheight < 1) previewheight = 1;

View file

@ -75,7 +75,7 @@ namespace CodeImp.DoomBuilder.Data
lock(this)
{
// No failure checking here. I anything fails here, it is not the user's fault,
// No failure checking here. If anything fails here, it is not the user's fault,
// because the resources this loads are in the assembly.
// Get resource from memory

View file

@ -55,6 +55,9 @@ namespace CodeImp.DoomBuilder.Data
// This 'loads' the image
protected override void LocalLoadImage()
{
//mxd. Leave when already loaded
if(this.IsImageLoaded) return;
bitmap = loadbitmap;
base.LocalLoadImage();
}

View file

@ -1,10 +1,10 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:2.0.50727.4927
// This code was generated by a tool.
// Runtime Version:2.0.50727.4927
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
@ -13,12 +13,12 @@ namespace CodeImp.DoomBuilder.Properties {
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
@ -33,7 +33,7 @@ namespace CodeImp.DoomBuilder.Properties {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
@ -47,8 +47,8 @@ namespace CodeImp.DoomBuilder.Properties {
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
@ -312,6 +312,13 @@ namespace CodeImp.DoomBuilder.Properties {
}
}
internal static System.Drawing.Bitmap MissingThing {
get {
object obj = ResourceManager.GetObject("MissingThing", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
internal static System.Drawing.Bitmap MLogo {
get {
object obj = ResourceManager.GetObject("MLogo", resourceCulture);

View file

@ -394,4 +394,7 @@
<data name="Unlink" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Unlink.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="MissingThing" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\MissingThing.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B