summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorDeeJayLSP <djlsplays@gmail.com>2024-08-28 16:47:32 -0300
committerDeeJayLSP <djlsplays@gmail.com>2024-08-28 16:47:32 -0300
commit7e49c26729f806c10d0c640c661fc8191d74eebf (patch)
tree0ea7403bca7e43f70491ef6035a613b2c0bff48e /modules
parentdb76de5de8a415b29be4c7dd84b99bd0fe260822 (diff)
downloadredot-engine-7e49c26729f806c10d0c640c661fc8191d74eebf.tar.gz
MP3: Use heap for big struct when setting data
Diffstat (limited to 'modules')
-rw-r--r--modules/minimp3/audio_stream_mp3.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/modules/minimp3/audio_stream_mp3.cpp b/modules/minimp3/audio_stream_mp3.cpp
index 5720f844bb..305c5c92a2 100644
--- a/modules/minimp3/audio_stream_mp3.cpp
+++ b/modules/minimp3/audio_stream_mp3.cpp
@@ -224,15 +224,19 @@ void AudioStreamMP3::set_data(const Vector<uint8_t> &p_data) {
int src_data_len = p_data.size();
const uint8_t *src_datar = p_data.ptr();
- mp3dec_ex_t mp3d;
- int err = mp3dec_ex_open_buf(&mp3d, src_datar, src_data_len, MP3D_SEEK_TO_SAMPLE);
- ERR_FAIL_COND_MSG(err || mp3d.info.hz == 0, "Failed to decode mp3 file. Make sure it is a valid mp3 audio file.");
+ mp3dec_ex_t *mp3d = memnew(mp3dec_ex_t);
+ int err = mp3dec_ex_open_buf(mp3d, src_datar, src_data_len, MP3D_SEEK_TO_SAMPLE);
+ if (err || mp3d->info.hz == 0) {
+ memdelete(mp3d);
+ ERR_FAIL_MSG("Failed to decode mp3 file. Make sure it is a valid mp3 audio file.");
+ }
- channels = mp3d.info.channels;
- sample_rate = mp3d.info.hz;
- length = float(mp3d.samples) / (sample_rate * float(channels));
+ channels = mp3d->info.channels;
+ sample_rate = mp3d->info.hz;
+ length = float(mp3d->samples) / (sample_rate * float(channels));
- mp3dec_ex_close(&mp3d);
+ mp3dec_ex_close(mp3d);
+ memdelete(mp3d);
clear_data();