From 07958ec36b62432f337f5cb6c5323a816f206f3f Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 2 May 2020 11:16:03 +0200 Subject: [PATCH] Fixed a crash --- native/serverconnection/src/audio/AudioOutput.cpp | 8 ++++---- native/serverconnection/src/ring_buffer.cpp | 6 ++++++ native/serverconnection/src/ring_buffer.h | 3 ++- native/updater/main.cpp | 2 +- package.json | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/native/serverconnection/src/audio/AudioOutput.cpp b/native/serverconnection/src/audio/AudioOutput.cpp index 43cac42..52de3a1 100644 --- a/native/serverconnection/src/audio/AudioOutput.cpp +++ b/native/serverconnection/src/audio/AudioOutput.cpp @@ -25,15 +25,15 @@ void AudioOutputSource::do_fade_out(size_t pop_count) { if(auto fn = this->on_underflow; fn && fn(0)) goto _test_for_fade; - auto wptr = (float*) this->buffer.write_ptr(); auto total_samples = std::min(samples_left, this->fadeout_sample_length); if(total_samples == 0) return; //TODO Test against min_buffered_samples - for(size_t index{0}; index < total_samples; index++) { + auto wptr = (float*) this->buffer.calculate_backward_write_ptr(total_samples * this->channel_count * sizeof(float)); + for(size_t index{0}; index <= total_samples; index++) { const auto offset = (float) ((float) index / (float) total_samples); - const auto volume = log10f(1 - offset) / -2.71828182845904f; + const auto volume = log10f(offset) / -2.71828182845904f; for(int channel{0}; channel < this->channel_count; channel++) - *wptr-- *= volume; + *wptr++ *= volume; } log_trace(category::audio, tr("Will buffer due to fade out ({} | {})"), total_samples, *(float*) this->buffer.write_ptr()); diff --git a/native/serverconnection/src/ring_buffer.cpp b/native/serverconnection/src/ring_buffer.cpp index f1a9cd0..9f7e890 100644 --- a/native/serverconnection/src/ring_buffer.cpp +++ b/native/serverconnection/src/ring_buffer.cpp @@ -243,6 +243,12 @@ namespace tc { return this->memory.address + (offset % this->memory.capacity); } + char* ring_buffer::calculate_backward_write_ptr(size_t bytes) { + bytes %= this->memory.capacity; + auto offset{this->write_offset.load() + this->memory.capacity - bytes}; + return this->memory.address + (offset % this->memory.capacity); + } + const void* ring_buffer::read_ptr() const { auto offset{this->read_offset.load()}; return this->memory.address + (offset % this->memory.capacity); diff --git a/native/serverconnection/src/ring_buffer.h b/native/serverconnection/src/ring_buffer.h index 41dec2f..3b67562 100644 --- a/native/serverconnection/src/ring_buffer.h +++ b/native/serverconnection/src/ring_buffer.h @@ -18,7 +18,8 @@ namespace tc { char* write_ptr(); void advance_write_ptr(size_t /* count */); - char* calculate_advanced_write_ptr(size_t /* count */bytes); + char* calculate_advanced_write_ptr(size_t /* count */); + char* calculate_backward_write_ptr(size_t /* count */); /* do not read more than the capacity! */ [[nodiscard]] const void* read_ptr() const; diff --git a/native/updater/main.cpp b/native/updater/main.cpp index f249186..f755267 100644 --- a/native/updater/main.cpp +++ b/native/updater/main.cpp @@ -118,7 +118,7 @@ int main(int argc, char** argv) { { auto admin = is_administrator(); logger::info("App executed as admin: %s", admin ? "yes" : "no"); - if(!admin && false) { + if(!admin) { logger::info("Requesting administrator rights"); if(!request_administrator(argc, argv)) { execute_callback_fail_exit("permissions", "failed to get administrator permissions"); diff --git a/package.json b/package.json index 192a12c..3426813 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "TeaClient", - "version": "1.4.6", + "version": "1.4.6-1", "description": "", "main": "main.js", "scripts": {