Skip to content

Commit 606d1c4

Browse files
committed
Crash when synchronizer is not defined
1 parent 813b848 commit 606d1c4

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/SnapClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ class SnapClient {
161161
AudioOutput *p_output = nullptr;
162162
AudioDecoder *p_decoder = nullptr;
163163
Client *p_client = nullptr;
164-
SnapTimeSync *p_time_sync = nullptr;
164+
SnapTimeSyncDynamic time_sync_default;
165+
SnapTimeSync *p_time_sync = &time_sync_default;
165166
IPAddress server_ip;
166167
int server_port = CONFIG_SNAPCAST_SERVER_PORT;
167168

src/api/SnapOutput.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class SnapOutput : public AudioInfoSupport {
132132
/// ignored - update playback speed
133133
bool synchronizePlayback() {
134134
bool result = true;
135+
assert(p_snap_time_sync!=nullptr);
136+
135137
SnapTimeSync &ts = *p_snap_time_sync;
136138

137139
// calculate how long we need to wait to playback the audio
@@ -170,8 +172,7 @@ class SnapOutput : public AudioInfoSupport {
170172
bool is_mute = false;
171173
SnapAudioHeader header;
172174
SnapTime &snap_time = SnapTime::instance();
173-
SnapTimeSyncDynamic time_sync_default;
174-
SnapTimeSync *p_snap_time_sync = &time_sync_default;
175+
SnapTimeSync *p_snap_time_sync = nullptr;
175176
bool is_sync_started = false;
176177
bool is_audio_begin_called = false;
177178

@@ -181,6 +182,10 @@ class SnapOutput : public AudioInfoSupport {
181182
ESP_LOGI(TAG, "out is null");
182183
return false;
183184
}
185+
if (p_snap_time_sync==nullptr){
186+
ESP_LOGI(TAG, "p_snap_time_sync is null");
187+
return false;
188+
}
184189

185190
// open volume control: allow amplification
186191
auto vol_cfg = vol_stream.defaultConfig();
@@ -241,6 +246,7 @@ class SnapOutput : public AudioInfoSupport {
241246
} else {
242247
// wait for the audio to become valid
243248
ESP_LOGI(TAG, "starting after %d ms", delay_ms);
249+
assert(p_snap_time_sync!=nullptr);
244250
setPlaybackFactor(p_snap_time_sync->getFactor());
245251
is_sync_started = true;
246252
result = true;
@@ -250,6 +256,7 @@ class SnapOutput : public AudioInfoSupport {
250256

251257
/// Calculate the delay in ms
252258
int getDelayMs() {
259+
assert(p_snap_time_sync!=nullptr);
253260
auto msg_time = snap_time.toMillis(header.sec, header.usec);
254261
auto server_time = snap_time.serverMillis();
255262
// wait for the audio to become valid

0 commit comments

Comments
 (0)