replace malloc/free with new/delete

master
Neirokan 2021-11-04 04:32:15 +03:00
parent a39fbaff47
commit bd013c5e43
3 changed files with 6 additions and 6 deletions

View File

@ -63,11 +63,11 @@ void Engine::create(int screenWidth, int screenHeight, const std::string &name,
GLfloat *model = it.second->glModel(); GLfloat *model = it.second->glModel();
GLfloat *geometry = Screen::glMeshToGLfloatArray(it.second, camera->position()); GLfloat *geometry = Screen::glMeshToGLfloatArray(it.second, camera->position());
screen->glDrawMesh(geometry, view, model, 3 * it.second->triangles().size()); screen->glDrawMesh(geometry, view, model, 3 * it.second->triangles().size());
free(geometry); delete[] geometry;
free(model); delete[] model;
} }
} }
free(view); delete[] view;
} else { } else {
// clear triangles from previous frame // clear triangles from previous frame
camera->clear(); camera->clear();

View File

@ -140,7 +140,7 @@ void Object::unattach(const ObjectNameTag &tag) {
// OpenGL function // OpenGL function
GLfloat *Object::glView() const { GLfloat *Object::glView() const {
auto *v = (GLfloat *) malloc(4 * 4 * sizeof(GLfloat)); auto *v = new GLfloat[4 * 4];
v[0] = -static_cast<GLfloat>(left().x()); v[0] = -static_cast<GLfloat>(left().x());
v[4] = -static_cast<GLfloat>(left().y()); v[4] = -static_cast<GLfloat>(left().y());
@ -166,7 +166,7 @@ GLfloat *Object::glView() const {
} }
GLfloat *Object::glModel() const { GLfloat *Object::glModel() const {
auto *m = (GLfloat *) malloc(4 * 4 * sizeof(GLfloat)); auto *m = new GLfloat[4 * 4];
m[0] = static_cast<GLfloat>(left().x()); m[0] = static_cast<GLfloat>(left().x());
m[4] = static_cast<GLfloat>(up().x()); m[4] = static_cast<GLfloat>(up().x());

View File

@ -173,7 +173,7 @@ void Screen::glDrawMesh(GLfloat *geometry, GLfloat *view, GLfloat *model, size_t
GLfloat *Screen::glMeshToGLfloatArray(std::shared_ptr<Mesh> mesh, const Vec3D &cameraPosition) { GLfloat *Screen::glMeshToGLfloatArray(std::shared_ptr<Mesh> mesh, const Vec3D &cameraPosition) {
std::vector<Triangle> const &triangles = mesh->triangles(); std::vector<Triangle> const &triangles = mesh->triangles();
auto *geometry = (GLfloat *) malloc(7 * 3 * triangles.size() * sizeof(GLfloat)); auto *geometry = new GLfloat[7 * 3 * triangles.size()];
auto model = mesh->model(); auto model = mesh->model();