1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Eliminates a couple of instances of manual memory management.

This commit is contained in:
Thomas Harte 2018-09-09 20:29:58 -04:00
parent 4c8781c762
commit c73445199c
2 changed files with 7 additions and 10 deletions

View File

@ -239,17 +239,16 @@ void Shader::set_uniform_matrix(const std::string &name, GLint size, bool transp
void Shader::set_uniform_matrix(const std::string &name, GLint size, GLsizei count, bool transpose, const GLfloat *values) { void Shader::set_uniform_matrix(const std::string &name, GLint size, GLsizei count, bool transpose, const GLfloat *values) {
std::size_t number_of_values = static_cast<std::size_t>(count) * static_cast<std::size_t>(size) * static_cast<std::size_t>(size); std::size_t number_of_values = static_cast<std::size_t>(count) * static_cast<std::size_t>(size) * static_cast<std::size_t>(size);
GLfloat *values_copy = new GLfloat[number_of_values]; std::vector<GLfloat> values_copy(number_of_values);
std::memcpy(values_copy, values, sizeof(*values) * number_of_values); std::memcpy(values_copy.data(), values, sizeof(*values) * number_of_values);
enqueue_function([name, size, count, transpose, values_copy, this] { enqueue_function([name, size, count, transpose, values_copy, this] {
GLboolean glTranspose = transpose ? GL_TRUE : GL_FALSE; GLboolean glTranspose = transpose ? GL_TRUE : GL_FALSE;
switch(size) { switch(size) {
case 2: glUniformMatrix2fv(location(), count, glTranspose, values_copy); break; case 2: glUniformMatrix2fv(location(), count, glTranspose, values_copy.data()); break;
case 3: glUniformMatrix3fv(location(), count, glTranspose, values_copy); break; case 3: glUniformMatrix3fv(location(), count, glTranspose, values_copy.data()); break;
case 4: glUniformMatrix4fv(location(), count, glTranspose, values_copy); break; case 4: glUniformMatrix4fv(location(), count, glTranspose, values_copy.data()); break;
} }
delete[] values_copy;
}); });
} }

View File

@ -173,10 +173,8 @@ void FileHolder::ensure_is_at_least_length(long length) {
std::fseek(file_, 0, SEEK_END); std::fseek(file_, 0, SEEK_END);
long bytes_to_write = length - ftell(file_); long bytes_to_write = length - ftell(file_);
if(bytes_to_write > 0) { if(bytes_to_write > 0) {
uint8_t *empty = new uint8_t[static_cast<std::size_t>(bytes_to_write)]; std::vector<uint8_t> empty(static_cast<std::size_t>(bytes_to_write), 0);
std::memset(empty, 0, static_cast<std::size_t>(bytes_to_write)); std::fwrite(empty.data(), sizeof(uint8_t), static_cast<std::size_t>(bytes_to_write), file_);
std::fwrite(empty, sizeof(uint8_t), static_cast<std::size_t>(bytes_to_write), file_);
delete[] empty;
} }
} }