Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Torrunt

Pages: [1] 2
1
DotNet / Re: Semi-random crashes when creating Textures
« on: November 19, 2018, 11:46:47 am »
I managed to get texture loading working fine using this:

Code: [Select]
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;
}

I noticed that if I pass null to glTexImage2D instead of the pixel byte array I get the same problem as before.
Seems like SFML in Texture::create, passes null to it as well:
https://github.com/SFML/SFML/blob/ff87e1c92265574f5c9785117b00907b7a61cf7d/src/SFML/Graphics/Texture.cpp#L208

Not sure why that is causing issues, or if that is the true cause or not.

2
DotNet / Re: Semi-random crashes when creating Textures
« on: November 16, 2018, 02:18:05 pm »
Hmmm... using Texture.Update instead doesn't cause a crash but the GPU memory doesn't go up at all while the system memory does. Though the working set stays around 1.3-1.4GB while containing to load textures past 40.

That's with replacing the Texture.Bind code with: texture.Update(IL.GetImageData());


I'll test out and see what happens when I try to load images in via something different than DevIL.

3
DotNet / Re: Semi-random crashes when creating Textures
« on: November 16, 2018, 01:13:14 pm »
Was messing around with my SFML.Net test again today. I can get it to work correctly if I create a new texture (without passing a file name or stream) then use Texture.Bind and OpenGL (glTexImage2D) to load in the texture. Doing that seems to place the textures in the GPU memory and not the system memory.

Here's the code I used:
(just grabbed the code for image loading via DevIL that I use for another project)

Code: [Select]
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;
        }

    }
}

I might have to just do a work-around like this for my game for now. Though I probably won't use DevIL since my game only needs to load pngs.

4
DotNet / Re: Semi-random crashes when creating Textures
« on: November 15, 2018, 11:22:56 am »
Yep, same results no matter which version of SFML/CSFML/SFML.Net I use.

5
DotNet / Re: Semi-random crashes when creating Textures
« on: November 15, 2018, 11:02:27 am »
I'm using the latest stuff on GitHub. I just downloaded 2.2 to quickly test the 64bit version.

6
DotNet / Re: Semi-random crashes when creating Textures
« on: November 15, 2018, 10:24:52 am »
Same code as before, just using the 2.2 64-bit dlls from: https://www.sfml-dev.org/download/sfml.net/
Code: [Select]
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);
            }
        }
    }
}

7
DotNet / Re: Semi-random crashes when creating Textures
« on: November 15, 2018, 08:52:32 am »
Well that's using the 64bit version, so that's with hundreds of textures and not just 40 like before. Also I was only looking at Task Manager before (and not the Resource Manager) which still only shows it using less than 100MB.

Edit: The working set for the 32bit version (when it crashes after loading around 40 textures) is 1.5GB

8
DotNet / Re: Semi-random crashes when creating Textures
« on: November 15, 2018, 08:38:10 am »
I tried the SFML.net (C++) test again today and it resulted in a std::bad_alloc: crash... It makes more sense that it crashes the same as the CSFML and SFML.net tests but why in the hell was it working fine the last couple of days when I tested it?? :S
My Windows updated last night but I'm not sure if that would have affected it at all...


I also tried the SFML.Net test today as a 64bit build (everything before was using 32bit) and it manages to create a lot more textures but it still looks like they are being stored in the system RAM and not the GPU RAM.



The working set keeps rising as more textures are made while the GPU memory doesn't budge at all.

9
DotNet / Re: Semi-random crashes when creating Textures
« on: November 13, 2018, 06:30:21 pm »
It's just an array ( sf::Texture textures[400]; ).

10
DotNet / Re: Semi-random crashes when creating Textures
« on: November 13, 2018, 05:23:29 pm »
The code is pretty much the same for all the tests. I even made it so it adds the textures to an array and the SFML test can still load in hundreds without any problems.

SFML (C++), no issues:
Code: [Select]
for (int i = 0; i < 200; i++)
{
sf::Texture texture;
if (texture.loadFromFile("image.png"))
textures[i] = texture;
}

SFML.Net, eventually results in LoadingFailedException:
Code: [Select]
for (int i = 0; i < 200; i++)
{
    Texture texture = new Texture("image.png");
}

CSFML, eventually results in std::bad_alloc:
Code: [Select]
for (int i = 0; i < 200; i++)
{
sfTexture* texture = sfTexture_createFromFile("image.png", NULL);
}

Same things happens for the SFML.Net and CSFML tests if I add the textures to lists/arrays like the SFML one.

11
DotNet / Re: Semi-random crashes when creating Textures
« on: November 13, 2018, 02:55:02 pm »
Here's the CSFML test code I used which results in the std::bad_alloc:
Code: [Select]
for (int i = 0; i < 200; i++)
{
sfTexture* texture = sfTexture_createFromFile("image.png", NULL);
}

I assume the std::bad_alloc there and the LoadingFailedException I get in the SFML.Net test are related.
It's weird that doing in directly in SFML (C++) works without any problems though...

12
DotNet / Re: Semi-random crashes when creating Textures
« on: November 13, 2018, 12:01:31 pm »
With that particular image it's always after the 40th time. Though another image I tested get's it randomly between the 125th and 130th time.

I can get SFML to load the texture in hundreds of times in a row with no problems at all. Though if I change the code to create and load images instead of textures; I get the std::bad_alloc.

Code: [Select]
// no problems:
for (int i = 0; i < 200; i++)
{
sf::Texture texture;
if (texture.loadFromFile("image.png"))
textures[i] = texture;
}
// crashes after loading 40:
for (int i = 0; i < 200; i++)
{
sf::Image image;
if (image.loadFromFile("image.png"))
images[i] = image;
}

13
Window / Re: SFML: Transparent Window Background?
« on: November 13, 2018, 11:13:35 am »
I manged to do this for Windows using DwmEnableBlurBehindWindow, which is a Desktop Window Manager API function.

You can see it in use here:
https://github.com/Torrunt/vimage/blob/master/vimage/Source/ImageViewer.cs#L109

That's using C# but you should be able to do it with C++ as well:
https://docs.microsoft.com/en-us/windows/desktop/api/dwmapi/nf-dwmapi-dwmenableblurbehindwindow

Then when you clear your window during you draw call, clear it with a colour that has some transparency.

14
DotNet / Re: Semi-random crashes when creating Textures
« on: November 13, 2018, 10:35:50 am »
According to Task Manager the GPU Memory doesn't go up much at all (was 1.7/19.0 GB before launch and stayed there). The main image I'm testing with is 4782x2064, and it crashes after loading it for the 40th time.

I tested the same thing in SFML and there was no problems. With CSFML I got this exception:
Quote
Exception thrown at 0x772A17D2 in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0133F6D8

15
DotNet / Re: Semi-random crashes when creating Textures
« on: November 13, 2018, 09:14:22 am »
All the images used are pngs, most with transparency.

I can get the exception simply by making a loop that constantly makes new textures.

Code: [Select]
for (int i = 0; i < 400; i++)
{
    Texture texture = new Texture("test.png");
}

The crash occurs after looping around 40-120 times. I tried with different images, ones with and without transparency, pngs, jpegs and gifs. When it crashes the programs is hardly using any Memory (less than 100MB) and less than 1% of the GPU.

I can stop that test code from crashing if I add all the textures to a list and start disposing them if the list becomes larger than 20. But it should be able to handle much more than that.

Pages: [1] 2
anything