mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-09 21:54:09 +08:00
fix: address potential GPU resource leaks
This commit is contained in:
@@ -36,7 +36,7 @@ private:
|
||||
|
||||
public:
|
||||
Player(const World& world, const std::string& name);
|
||||
|
||||
~Player();
|
||||
const glm::vec3& get_front() const;
|
||||
const glm::vec3& get_player_pos() const;
|
||||
const MoveState& get_move_state() const;
|
||||
|
||||
@@ -8,7 +8,7 @@ Chunk::Chunk(World& world, ChunkPos chunk_pos) :
|
||||
}
|
||||
|
||||
Chunk::~Chunk() {
|
||||
|
||||
glDeleteBuffers(1, &m_vbo);
|
||||
}
|
||||
|
||||
const std::vector<uint8_t>& Chunk::get_chunk_blocks() const{
|
||||
|
||||
@@ -8,7 +8,9 @@ Player::Player(const World& world, const std::string& name) :
|
||||
{
|
||||
|
||||
}
|
||||
Player::~Player() {
|
||||
|
||||
}
|
||||
const glm::vec3& Player::get_front() const {
|
||||
return m_front;
|
||||
}
|
||||
|
||||
23
src/main.cpp
23
src/main.cpp
@@ -18,9 +18,6 @@
|
||||
#include <Cubed/tools/shader_tools.hpp>
|
||||
|
||||
constexpr int NUM_VAO = 1;
|
||||
constexpr int NUM_VBO = 1;
|
||||
|
||||
|
||||
|
||||
GLuint rendering_program;
|
||||
GLuint vao[NUM_VAO];
|
||||
@@ -39,15 +36,9 @@ World world;
|
||||
|
||||
|
||||
void setup_vertices(void) {
|
||||
|
||||
|
||||
// every block
|
||||
|
||||
|
||||
|
||||
glGenVertexArrays(NUM_VAO, vao);
|
||||
glBindVertexArray(vao[0]);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
@@ -93,7 +84,8 @@ GLuint create_shader_program() {
|
||||
LOG::error("linking failed");
|
||||
Shader::print_program_info(vf_program);
|
||||
}
|
||||
|
||||
glDeleteShader(v_shader);
|
||||
glDeleteShader(f_shader);
|
||||
return vf_program;
|
||||
}
|
||||
|
||||
@@ -169,7 +161,7 @@ void display(GLFWwindow* window, double current_time) {
|
||||
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||||
switch(key) {
|
||||
case GLFW_KEY_ESCAPE:
|
||||
case GLFW_KEY_Q:
|
||||
if (action == GLFW_PRESS) {
|
||||
|
||||
if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) {
|
||||
@@ -179,6 +171,10 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GLFW_KEY_ESCAPE:
|
||||
if (action == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -221,7 +217,10 @@ int main() {
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
glDeleteVertexArrays(NUM_VAO, vao);
|
||||
glDeleteProgram(rendering_program);
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
Reference in New Issue
Block a user