From af9b049057eb504bbf0de948fbe15a589b10912d Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 3 Nov 2019 15:52:19 +0100 Subject: [PATCH] fixed the rug becoming black on some computers when resizing window or during the start animation --- basegraph.cpp | 5 +---- changelog.txt | 1 + rug.cpp | 29 +++++++++++++++++++++-------- screenshot.cpp | 1 + 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/basegraph.cpp b/basegraph.cpp index 7f1089dc..ea82f4a0 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -600,10 +600,7 @@ EX void resetGL() { matched_programs.clear(); glhr::current_glprogram = nullptr; ray::reset_raycaster(); - if(rug::rugged) { - rug::close(); - rug::reopen(); - } + if(rug::glbuf) rug::close_glbuf(); } #endif diff --git a/changelog.txt b/changelog.txt index e7d0e01d..80991805 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3595,3 +3595,4 @@ Other: - hell unlock message on 10th shard - levellines feature: shade rendered output by Z coordinate (nice in Hypersian Rug mode) - fixed the overlay in the texture mode (also disabled in ray -- not implemented) +- fixed the rug becoming black on some computers when resizing window or during the start animation diff --git a/rug.cpp b/rug.cpp index d9596444..497f8ca7 100644 --- a/rug.cpp +++ b/rug.cpp @@ -1287,6 +1287,8 @@ void drawTriangle(triangle& t) { EX struct renderbuffer *glbuf; EX void prepareTexture() { + ensure_glbuf(); + if(!glbuf) { rug::close(); return; } resetbuffer rb; dynamicval d(vid.stereo_mode, sOFF); @@ -1446,18 +1448,29 @@ EX void drawRugScene() { //-------------- EX transmatrix currentrot; - + +EX void close_glbuf() { + delete glbuf; + glbuf = nullptr; + } + +EX void ensure_glbuf() { + if(glbuf) return; + glbuf = new renderbuffer(TEXTURESIZE, TEXTURESIZE, vid.usingGL && !rendernogl); + if(!glbuf->valid) { + addMessage(XLAT("Failed to enable")); + close_glbuf(); + return; + } + } + EX void reopen() { if(rugged) return; rugdim = 2 * GDIM - 1; when_enabled = 0; GLERR("before init"); - glbuf = new renderbuffer(TEXTURESIZE, TEXTURESIZE, vid.usingGL && !rendernogl); - if(!glbuf->valid) { - addMessage(XLAT("Failed to enable")); - delete glbuf; - return; - } + ensure_glbuf(); + if(!glbuf) { rugged = false; return; } rugged = true; if(renderonce) prepareTexture(); if(!rugged) return; @@ -1527,7 +1540,7 @@ EX void clear_model() { EX void close() { if(!rugged) return; rugged = false; - delete glbuf; + close_glbuf(); finger_center = NULL; } diff --git a/screenshot.cpp b/screenshot.cpp index b1a13635..5930fc1d 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -1172,6 +1172,7 @@ void rug() { rug::apply_rotation(cspin(1, 2, ticks / 3000.)); gamescreen(2); rug::apply_rotation(cspin(1, 2, -ticks / 3000.)); + if(!rug::rugged) current = null_animation; } #endif