Add GCHandle to StbiStreamWrapper in TryLoad routines.
All checks were successful
Build / build (push) Successful in 1m56s
All checks were successful
Build / build (push) Successful in 1m56s
This commit is contained in:
parent
09b5238b24
commit
6ffcd38cbc
@ -14,7 +14,7 @@
|
|||||||
<!-- Nuget Properties. -->
|
<!-- Nuget Properties. -->
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
<PackageId>ReFuel.StbImage</PackageId>
|
<PackageId>ReFuel.StbImage</PackageId>
|
||||||
<Version>2.0.2-rc.0</Version>
|
<Version>2.0.2-rc.1</Version>
|
||||||
<Authors>STBI Authors, H. Utku Maden</Authors>
|
<Authors>STBI Authors, H. Utku Maden</Authors>
|
||||||
<Description>
|
<Description>
|
||||||
A C# wrapper for the ubiquitous stb_image.h and stb_image_write.h library.
|
A C# wrapper for the ubiquitous stb_image.h and stb_image_write.h library.
|
||||||
@ -27,7 +27,9 @@
|
|||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<PackageTags>stb; stb_image; stbi; image; load; save; read; write</PackageTags>
|
<PackageTags>stb; stb_image; stbi; image; load; save; read; write</PackageTags>
|
||||||
<PackageReleaseNotes># 2.0.2
|
<PackageReleaseNotes># 2.0.2
|
||||||
* Fixed calling convention related execution engine exception for the Windows platform.
|
* Fixed calling convention of unmanaged function pointers. (Thanks NogginBops!)
|
||||||
|
* Allocating a GC handle to StbiStreamWrapper class and passing it as userdata into stbi in order to prevent
|
||||||
|
the object from being prematurely collected by the garbage collector when optimizations are enabled in Release mode.
|
||||||
|
|
||||||
# 2.0.1
|
# 2.0.1
|
||||||
* Enabled optimizations across the board for native and managed assemblies.
|
* Enabled optimizations across the board for native and managed assemblies.
|
||||||
|
@ -209,17 +209,19 @@ namespace ReFuel.Stb
|
|||||||
{
|
{
|
||||||
int x, y, iFormat;
|
int x, y, iFormat;
|
||||||
StbiStreamWrapper wrapper = new StbiStreamWrapper(stream, true);
|
StbiStreamWrapper wrapper = new StbiStreamWrapper(stream, true);
|
||||||
|
GCHandle gch = GCHandle.Alloc(wrapper, GCHandleType.Normal);
|
||||||
wrapper.CreateCallbacks(out stbi_io_callbacks cb);
|
wrapper.CreateCallbacks(out stbi_io_callbacks cb);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
IntPtr imagePtr;
|
IntPtr imagePtr;
|
||||||
if (asFloat)
|
if (asFloat)
|
||||||
{
|
{
|
||||||
imagePtr = (IntPtr)Stbi.loadf_from_callbacks(&cb, null, &x, &y, &iFormat, (int)format);
|
imagePtr = (IntPtr)Stbi.loadf_from_callbacks(&cb, (void*)(IntPtr)gch, &x, &y, &iFormat, (int)format);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
imagePtr = (IntPtr)Stbi.load_from_callbacks(&cb, null, &x, &y, &iFormat, (int)format);
|
imagePtr = (IntPtr)Stbi.load_from_callbacks(&cb, (void*)(IntPtr)gch, &x, &y, &iFormat, (int)format);
|
||||||
}
|
}
|
||||||
|
gch.Free();
|
||||||
|
|
||||||
if (imagePtr != IntPtr.Zero)
|
if (imagePtr != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user