diff --git a/.vs/Switch_Toolbox/v15/.suo b/.vs/Switch_Toolbox/v15/.suo index 2ea9e5bb..32f60229 100644 Binary files a/.vs/Switch_Toolbox/v15/.suo and b/.vs/Switch_Toolbox/v15/.suo differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide index 44626d6d..9e19b2bd 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal index d4c32cba..96becdce 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal differ diff --git a/Switch_FileFormatsMain/FileFormats/Texture/GTXFile.cs b/Switch_FileFormatsMain/FileFormats/Texture/GTXFile.cs index cbfc74d6..cdf0313b 100644 --- a/Switch_FileFormatsMain/FileFormats/Texture/GTXFile.cs +++ b/Switch_FileFormatsMain/FileFormats/Texture/GTXFile.cs @@ -593,7 +593,7 @@ namespace FirstPlugin surface.tileMode = NewSurface.tileMode; surface.use = NewSurface.use; surface.width = NewSurface.width; - surface.texRegs = GX2.CreateRegisters(NewSurface); + surface.texRegs = NewSurface.texRegs; SetChannelComponents(); } @@ -637,33 +637,26 @@ namespace FirstPlugin surface.numMips = MipCount; surface.mipOffset = new uint[MipCount]; - try - { - //Create image block from bitmap first - var data = GenerateMipsAndCompress(bitmap, MipCount, Format); + //Create image block from bitmap first + var data = GenerateMipsAndCompress(bitmap, MipCount, Format); - //Swizzle and create surface - var NewSurface = GX2.CreateGx2Texture(data, Text, - (uint)surface.tileMode, - (uint)surface.aa, - (uint)surface.width, - (uint)surface.height, - (uint)surface.depth, - (uint)surface.format, - (uint)surface.swizzle, - (uint)surface.dim, - (uint)surface.numMips - ); + //Swizzle and create surface + var NewSurface = GX2.CreateGx2Texture(data, Text, + (uint)surface.tileMode, + (uint)surface.aa, + (uint)surface.width, + (uint)surface.height, + (uint)surface.depth, + (uint)surface.format, + (uint)surface.swizzle, + (uint)surface.dim, + (uint)surface.numMips + ); - ApplySurface(NewSurface); - IsEdited = true; - LoadOpenGLTexture(); - LibraryGUI.UpdateViewport(); - } - catch (Exception ex) - { - STErrorDialog.Show("Failed to swizzle and compress image " + Text, "Error", ex.ToString()); - } + ApplySurface(NewSurface); + IsEdited = true; + LoadOpenGLTexture(); + LibraryGUI.UpdateViewport(); } public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0) diff --git a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache index b489509e..71c753b9 100644 Binary files a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache and b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache differ diff --git a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache index 475a9910..5fa02d76 100644 Binary files a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache and b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache differ diff --git a/Switch_Toolbox_Library/Forms/Editors/ImageEditor/ImageEditorBase.cs b/Switch_Toolbox_Library/Forms/Editors/ImageEditor/ImageEditorBase.cs index 5d825bbe..c28ec625 100644 --- a/Switch_Toolbox_Library/Forms/Editors/ImageEditor/ImageEditorBase.cs +++ b/Switch_Toolbox_Library/Forms/Editors/ImageEditor/ImageEditorBase.cs @@ -710,6 +710,8 @@ namespace Switch_Toolbox.Library.Forms private void UpdateEdit(Image image) { + if (ActiveTexture.ArrayCount == 0) ActiveTexture.ArrayCount = 1; + ActiveTexture.EditedImages = new EditedBitmap[ActiveTexture.ArrayCount]; ActiveTexture.EditedImages[CurArrayDisplayLevel] = new EditedBitmap() { @@ -751,7 +753,8 @@ namespace Switch_Toolbox.Library.Forms if (ActiveTexture.EditedImages != null && ActiveTexture.EditedImages[CurArrayDisplayLevel] != null) { - ActiveTexture.EditedImages[CurArrayDisplayLevel].bitmap.Dispose(); + if (ActiveTexture.EditedImages[CurArrayDisplayLevel].bitmap != null) + ActiveTexture.EditedImages[CurArrayDisplayLevel].bitmap.Dispose(); ActiveTexture.EditedImages[CurArrayDisplayLevel] = null; } @@ -1031,6 +1034,9 @@ namespace Switch_Toolbox.Library.Forms public void SaveAndApplyImage(Bitmap image, bool DecodeBack) { + if (image == null) + return; + if (saveBtn.InvokeRequired) { saveBtn.Invoke(new MethodInvoker( diff --git a/Switch_Toolbox_Library/Swizzling/GX2.cs b/Switch_Toolbox_Library/Swizzling/GX2.cs index b953009b..0f26ca2d 100644 --- a/Switch_Toolbox_Library/Swizzling/GX2.cs +++ b/Switch_Toolbox_Library/Swizzling/GX2.cs @@ -612,6 +612,8 @@ namespace Switch_Toolbox.Library.Old surf.alignment = alignment; surf.imageSize = imageSize; surf.data = Swizzled[0]; + surf.compSel = new byte[4] { 0, 1, 2, 3 }; + surf.texRegs = CreateRegisters(surf); List mips = new List(); for (int mipLevel = 1; mipLevel < Swizzled.Count; mipLevel++) diff --git a/Switch_Toolbox_Library/Swizzling/GX2TexRegisters.cs b/Switch_Toolbox_Library/Swizzling/GX2TexRegisters.cs index e2b03d7d..7487167c 100644 --- a/Switch_Toolbox_Library/Swizzling/GX2TexRegisters.cs +++ b/Switch_Toolbox_Library/Swizzling/GX2TexRegisters.cs @@ -70,6 +70,9 @@ namespace Switch_Toolbox.Library public static uint[] CreateTexRegs(uint width, uint height, uint numMips, uint format_, uint tileMode, uint pitch, byte[] compSel) { + if (compSel == null || compSel.Length != 4) + compSel = new byte[4] { 0, 1, 2, 3 }; + pitch = Math.Max(pitch, 8); var register0 = _register0((int)width - 1, (int)(pitch / 8) - 1, 0, (int)tileMode, 1); @@ -106,7 +109,7 @@ namespace Switch_Toolbox.Library byte[] reg3 = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(register3)); byte[] reg4 = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(register4));*/ - return new uint[] { (uint)register0, (uint)register1, (uint)register2, (uint)register3, (uint)register4 }; + return new uint[5] { (uint)register0, (uint)register1, (uint)register2, (uint)register3, (uint)register4 }; } } diff --git a/Switch_Toolbox_Library/Swizzling/NewSwizzleCodeBackup.cs b/Switch_Toolbox_Library/Swizzling/NewSwizzleCodeBackup.cs index f030002b..7668cc1a 100644 --- a/Switch_Toolbox_Library/Swizzling/NewSwizzleCodeBackup.cs +++ b/Switch_Toolbox_Library/Swizzling/NewSwizzleCodeBackup.cs @@ -557,6 +557,7 @@ namespace Switch_Toolbox.Library surf.alignment = alignment; surf.imageSize = imageSize; surf.data = Swizzled[0]; + surf.texRegs = CreateRegisters(surf); List mips = new List(); for (int mipLevel = 1; mipLevel < Swizzled.Count; mipLevel++)