SpiderPig Posted May 28 Share Posted May 28 The following code will increase memory usage to about 12 GB before it goes back down to a normal amount. My game gets up to 40GB with no signs of slowing. #include "Engine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { auto displays = GetDisplays(); auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); auto framebuffer = CreateFramebuffer(window); auto world = CreateWorld(); auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetPosition(0, 2, -6); camera->SetDebugPhysicsMode(true); auto light = CreateDirectionalLight(world); light->SetRotation(35, 35, 0); light->SetColor(3); auto size = 512; auto buffer = CreateBuffer(size * size * 4); auto texture = CreateTexture(TEXTURE_2D, size, size); for (int i = 0; i < 10000; i++) { texture->SetPixels(buffer);//The more this is called the worse the leak! } //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; } Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted May 29 Solution Share Posted May 29 This algorithm creates an intermediate buffer that gets passed to the rendering thread. It's working as I would expect. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted May 29 Author Share Posted May 29 Ah okay. Well that's okay. I just need to change how I'm updating the texture then. Is it okay to do this in a render hook? Are render hooks before render or after? RenderHook() { texture->SetPixels(buffer); } Quote Link to comment Share on other sites More sharing options...
Josh Posted May 29 Share Posted May 29 9 minutes ago, SpiderPig said: Ah okay. Well that's okay. I just need to change how I'm updating the texture then. Is it okay to do this in a render hook? Are render hooks before render or after? RenderHook() { texture->SetPixels(buffer); } Why? Transfer buffers are a very common technique. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted May 29 Author Share Posted May 29 I have a texture for holding a lot of variables for shaders. Sometimes those variables change, like 10'000 times at startup but only one or twice during game. So I do need to get the updating variable to the shaders. Quote Link to comment Share on other sites More sharing options...
Josh Posted May 29 Share Posted May 29 You might want to change your design so some global variable gets set when something is changed, and then just submit the changes once if they occur. This is how I handle changes to mesh data, instead of submitting the mesh each time it just adds it to a list of meshes that need to be sent, and all updated meshes are submitted right before the render. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted May 29 Author Share Posted May 29 Yeah this is what I will do I think. That's why I was wondering if it's okay to update the texture with the new buffer in the render hook. It will look more like this. RenderHook() { if(changes == true){ changes = false; texture->SetPixels(buffer); } } Quote Link to comment Share on other sites More sharing options...
Josh Posted May 29 Share Posted May 29 As long as "changes" is not a variable both threads can access! But I would just use SetPixels from the main thread, it's safer and less likely to break down. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted May 29 Author Share Posted May 29 Okay thanks! I'll do that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.