diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 470a41f..fee200d 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1,5 +1,6 @@ #include "MainWindow.h" +#include "cuda_runtime.h" #include #include @@ -56,7 +57,7 @@ int Window::init(float* data) { Window::tick(); } - Window::free(); + Window::free(data); return 0; } @@ -73,10 +74,11 @@ int Window::init_quad(float* data) { } -void Window::free() { +void Window::free(float* data) { // To preserve the proper destruction order we forcefully set the quads to null (calling their destructor in the process) // Not strictly necessary, but i saw some weird errors on exit without this so best to keep it in. this->current_quad = nullptr; + cudaFree(data); glfwDestroyWindow(window); glfwTerminate(); diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 5d66530..e7d6c46 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -17,7 +17,7 @@ public: Window(unsigned int w, unsigned int h); int init(float* data); - void free(); + void free(float* data); void resize(unsigned int w, unsigned int h); private: diff --git a/src/illumination/FrameBuffer.cu b/src/illumination/FrameBuffer.cu index e04b865..f81af04 100644 --- a/src/illumination/FrameBuffer.cu +++ b/src/illumination/FrameBuffer.cu @@ -3,10 +3,11 @@ __host__ FrameBuffer::FrameBuffer(unsigned int w, unsigned int h) : w(w), h(h) { - this->buffer_size = w*h*4; + this->buffer_size = w*h*sizeof(unsigned int); + cudaMalloc((void**)&this->buffer, this->buffer_size); + cudaMemset(this->buffer, 0, this->buffer_size); } - __device__ void FrameBuffer::writePixel(int x, int y, float r, float g, float b) { int i = y * this->w + x; diff --git a/src/illumination/Raycaster.cu b/src/illumination/Raycaster.cu index b99e293..a405e25 100644 --- a/src/illumination/Raycaster.cu +++ b/src/illumination/Raycaster.cu @@ -168,7 +168,7 @@ void Raycaster::resize(int w, int h) { this->w = w; this->h = h; - delete fb; + delete this->fb; this->fb = new FrameBuffer(w, h); // TODO: should be globals probably