Skip to content

Commit

Permalink
fix tlg data GC causing AccessViolation issue #109
Browse files Browse the repository at this point in the history
  • Loading branch information
UlyssesWu committed May 31, 2023
1 parent f9e8f04 commit af91cd1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion FreeMote.Plugins/FreeMote.Plugins.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<WarningLevel>4</WarningLevel>
<LangVersion>default</LangVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -34,6 +34,7 @@
<WarningLevel>4</WarningLevel>
<LangVersion>default</LangVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -44,6 +45,7 @@
<LangVersion>default</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
Expand All @@ -54,6 +56,7 @@
<LangVersion>default</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
3 changes: 3 additions & 0 deletions FreeMote.Plugins/Shells/PsdShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using System.Text;
using FastBitmapLib;
using FreeMote.Plugins.Properties;
using FreeMote.Psb;
using PhotoshopFile;
Expand Down Expand Up @@ -610,6 +611,8 @@ class GroupLayer : ILayer
public void CreateLayers(PsdFile psd)
{
var beginLayer = psd.MakeSectionLayers(Name, out var endLayer, Open);
beginLayer.Visible = Object.TryGetValue("visible", out var visible) && visible.GetInt() != 0;
beginLayer.Opacity = (byte) (Object.TryGetValue("opacity", out var opacity) ? opacity.GetInt() : 255);
if (LayerId is >= 0 and <= PsdShell.MaxLayerId)
{
var idLayer = new LayerId((uint) LayerId);
Expand Down
7 changes: 6 additions & 1 deletion FreeMote/TlgImageConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal TlgMetaData ReadMetaData (BinaryReader br)
};
}

public Bitmap ReadAndGetMetaData(BinaryReader file, out TlgMetaData md)
public Bitmap ReadAndGetMetaData(BinaryReader file, out TlgMetaData md, bool copy = true)
{
TlgMetaData meta = ReadMetaData(file);
md = meta;
Expand All @@ -157,8 +157,13 @@ public Bitmap ReadAndGetMetaData(BinaryReader file, out TlgMetaData md)
Trace.WriteLine(x.Message, "[TlgFormat.Read]");
}
}

//PixelFormat format = 32 == meta.BPP ? PixelFormats.Bgra32 : PixelFormats.Bgr32;
PixelFormat format = 32 == meta.Bpp ? PixelFormat.Format32bppArgb : PixelFormat.Format32bppRgb;
if (copy)
{
return RL.ConvertToImage(image, (int) meta.Width, (int) meta.Height, PsbPixelFormat.LeRGBA8);
}
return CreateImage(meta, format, image, (int)meta.Width * 4);
}

Expand Down

0 comments on commit af91cd1

Please sign in to comment.