mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
memory-safety improved
This commit is contained in:
parent
779a8101fa
commit
6830205bcc
3 changed files with 59 additions and 32 deletions
|
|
@ -176,6 +176,7 @@ bool load_wav_file_header(std::ifstream& file,
|
|||
return true;
|
||||
}
|
||||
|
||||
// after that user must free returned memory by himself!
|
||||
char* load_wav(const std::string& filename,
|
||||
std::uint8_t& channels,
|
||||
std::int32_t& sampleRate,
|
||||
|
|
@ -192,8 +193,13 @@ char* load_wav(const std::string& filename,
|
|||
}
|
||||
|
||||
char* data = new char[size];
|
||||
|
||||
in.read(data, size);
|
||||
|
||||
return data;
|
||||
try {
|
||||
in.read(data, size);
|
||||
return data;
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
delete[] data;
|
||||
std::cerr << "ERROR: Could not load wav data of \"" << filename << "\"" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue