jam1garner / Smash-Forge

Open Source Editor of Smash 4 Filetypes
MIT License
147 stars 59 forks source link

Bfres botw Wii U texture2d access violation exception #283

Open ScanMountGoat opened 6 years ago

ScanMountGoat commented 6 years ago

This could be an issue with the format and dimensions. The crash is from GL.CompressedTexImage2D.

Passing the same parameters and an empty byte array of the same length into the method does not cause an exception with SFGraphics.

Error: Run Forge in debug mode in Visual Studio. Otherwise, the application will immediately exit. System.AccessViolationException

File: DgnObj_SwitchStepOnce_B.Tex1.sbfres.zip

ScanMountGoat commented 6 years ago

https://github.com/ScanMountGoat/SFGraphics/blob/master/Projects/SFGraphics/GLObjects/Textures/MipmapLoading.cs#L90-L103

 public static void LoadBaseLevelGenerateMipmaps<T>(TextureTarget textureTarget, int width, int height, 
            T[] baseMipLevel, int mipCount, InternalFormat internalFormat) where T : struct
        {
            // The number of mipmaps needs to be specified first.
            int maxMipLevel = Math.Max(mipCount - 1, minMipLevel);
            GL.TexParameter(textureTarget, TextureParameterName.TextureMaxLevel, maxMipLevel);

            // Calculate the proper imageSize.
            int baseImageSize = TextureFormatTools.CalculateImageSize(width, height, internalFormat);

            // Load the first level.
            GL.CompressedTexImage2D(textureTarget, 0, internalFormat, width, height, 0, baseImageSize, baseMipLevel);
            GL.GenerateMipmap((GenerateMipmapTarget)textureTarget);
        }