0 Members and 6 Guests are viewing this topic.
using System;using System.Collections.Generic;using SFML.Graphics;namespace TextureCrashTest{ class Program { static void Main(string[] args) { List<Texture> textures = new List<Texture>(); for (int i = 0; i < 400; i++) { Texture texture = new Texture("image.png"); textures.Add(texture); Console.WriteLine(i); } } }}
using System;using System.Collections.Generic;using System.IO;using SFML.Window;using SFML.System;using SFML.Graphics;using Tao.OpenGl;using DevIL.Unmanaged;namespace TextureCrashTest{ class Program { static void Main(string[] args) { IL.Initialize(); RenderWindow Window = new RenderWindow(new VideoMode(1920, 1080), "test", Styles.Default); Window.Size = new Vector2u(1920, 1080); Window.Position = new Vector2i(100, 100); List<Texture> textures = new List<Texture>(); for (int i = 0; i < 400; i++) { Texture texture = GetTexture("image.png"); textures.Add(texture); Console.WriteLine(i); } } private static Texture GetTexture(string filename) { int imageID = IL.GenerateImage(); IL.BindImage(imageID); IL.Enable(ILEnable.AbsoluteOrigin); IL.SetOriginLocation(DevIL.OriginLocation.UpperLeft); bool loaded = false; using (FileStream fileStream = File.OpenRead(filename)) loaded = IL.LoadImageFromStream(fileStream); if (!loaded) return null; bool success = IL.ConvertImage(DevIL.DataFormat.RGBA, DevIL.DataType.UnsignedByte); if (!success) return null; int width = IL.GetImageInfo().Width; int height = IL.GetImageInfo().Height; Texture texture = new Texture((uint)width, (uint)height); Texture.Bind(texture); { Gl.glTexImage2D( Gl.GL_TEXTURE_2D, 0, IL.GetInteger(ILIntegerMode.ImageBytesPerPixel), width, height, 0, IL.GetInteger(ILIntegerMode.ImageFormat), ILDefines.IL_UNSIGNED_BYTE, IL.GetData()); } Texture.Bind(null); IL.DeleteImages(new ImageID[] { imageID }); return texture; } }}
private static Texture GetTexture(Stream stream, IntRect area = default(IntRect)){ Image image = new Image(stream); Texture texture = new Texture(image.Size.X, image.Size.Y); if (area == default(IntRect)) area = new IntRect(0, 0, (int)image.Size.X, (int)image.Size.Y); Texture.Bind(texture); Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA, area.Width, area.Height, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, image.Pixels); Gl.glTexSubImage2D(Gl.GL_TEXTURE_2D, 0, area.Left, area.Top, area.Width, area.Height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, image.Pixels); Texture.Bind(null); return texture;}