History

Force stop WAV rendering if output file exceeds 2GB

Olav Sørensen committed 4 years ago

Commit 9cf2fd91 parent 8f2f0721 file · +21 −3Browse files

Unified · Split

src/ft2_wav_renderer.c+21−3
@@ -309,6 +309,8 @@ static void updateVisuals(void) · 308 unmodified lines
309309
310310 static int32_t SDLCALL renderWavThread(void *ptr)
311311 {
312+ (void)ptr;
313+
312314 FILE *f = (FILE *)editor.wavRendererFileHandle;
313315 fseek(f, sizeof (wavHeader_t), SEEK_SET);
314316
@@ -322,10 +324,12 @@ static int32_t SDLCALL renderWavThread(void *ptr) · 7 unmodified lines
322324 }
323325
324326 uint32_t sampleCounter = 0;
325− bool renderDone = false;
327+ bool overflow = false, renderDone = false;
326328 uint8_t tickCounter = 4;
327329 int64_t tickSampleCounter64 = 0;
328330
331+ uint64_t bytesInFile = sizeof (wavHeader_t);
332+
329333 editor.wavReachedEndFlag = false;
330334 while (!renderDone)
331335 {
@@ -358,9 +362,22 @@ static int32_t SDLCALL renderWavThread(void *ptr) · 26 unmodified lines
358362
359363 // increase buffer pointer
360364 if (WDBitDepth == 16)
365+ {
361366 ptr8 += remainingTick * sizeof (int16_t);
367+ bytesInFile += remainingTick * sizeof (int16_t);
368+ }
362369 else
370+ {
363371 ptr8 += remainingTick * sizeof (float);
372+ bytesInFile += remainingTick * sizeof (float);
373+ }
374+
375+ if (bytesInFile >= INT32_MAX)
376+ {
377+ renderDone = true;
378+ overflow = true;
379+ break;
380+ }
364381
365382 if (++tickCounter >= 4)
366383 {
@@ -385,10 +402,11 @@ static int32_t SDLCALL renderWavThread(void *ptr) · 18 unmodified lines
385402 dump_Close(f, sampleCounter);
386403 resumeAudio();
387404
405+ if (overflow)
406+ okBoxThreadSafe(0, "System message", "Rendering stopped, file exceeded 2GB!");
407+
388408 editor.diskOpReadOnOpen = true;
389409 return true;
390−
391− (void)ptr;
392410 }
393411
394412 static void wavRender(bool checkOverwrite)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t