From 267834b1ee62aa713b15c966446283d4cef9b7ab Mon Sep 17 00:00:00 2001 From: Chancy Kennedy Date: Mon, 12 Jul 2021 17:28:20 -0500 Subject: [PATCH] fix memory leak --- examples/realtime_sdl.nim | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/realtime_sdl.nim b/examples/realtime_sdl.nim index 4150059..09a86d8 100644 --- a/examples/realtime_sdl.nim +++ b/examples/realtime_sdl.nim @@ -2,6 +2,13 @@ import math, pixie, sdl2, sdl2/gfx + +const + rmask = uint32 0x000000ff + gmask = uint32 0x0000ff00 + bmask = uint32 0x00ff0000 + amask = uint32 0xff000000 + let w: int32 = 256 h: int32 = 256 @@ -16,6 +23,7 @@ var mainTexture: TexturePtr evt = sdl2.defaultEvent + proc display() = ## Called every frame by main while loop @@ -44,20 +52,19 @@ proc display() = inc frameCount var dataPtr = ctx.image.data[0].addr - mainSurface.pixels = dataPtr + mainSurface = createRGBSurfaceFrom(dataPtr, cint w, cint h, cint 32, cint 4*w, rmask, gmask, bmask, amask) mainTexture = render.createTextureFromSurface(mainSurface) + destroy(mainSurface) + + render.clear() render.copy(mainTexture, nil, nil) + destroy(mainTexture) + render.present() + discard sdl2.init(INIT_EVERYTHING) window = createWindow("SDL/Pixie", 100, 100, cint w, cint h, SDL_WINDOW_SHOWN) -const - rmask = uint32 0x000000ff - gmask = uint32 0x0000ff00 - bmask = uint32 0x00ff0000 - amask = uint32 0xff000000 -mainSurface = createRGBSurface(0, cint w, cint h, 32, rmask, gmask, bmask, amask) - render = createRenderer(window, -1, 0) while true: