Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix glitched graphics in undrawn area of the window #56215

Merged
merged 5 commits into from
Apr 2, 2022

Conversation

Qrox
Copy link
Contributor

@Qrox Qrox commented Mar 19, 2022

Summary

Bugfixes "Fix glitched graphics in undrawn area of the window"

Purpose of change

Fix two graphic glitches when alt-tabbing. Fixes #56064.

Describe the solution

For the first gitch, the undrawn area sometimes contain random pixels when alt-tabbing back, which is fixed by the following changes:

  1. Reinitialize the render target on SDL_RENDER_TARGETS_RESET event.
  2. Skip handling SDL_RENDER_TARGETS_RESET when game window is resized, because resizing already reinitializes the render target.
  3. It seems SDL_WINDOWEVENT_EXPOSED does not actually require a redraw, only a update of the screen, so skip redrawing for SDL_WINDOWEVENT_EXPOSED.

For the second glitch, the undrawn area contains terrain graphics normally not drawn there after a debug message is shown during the terrain redraw callback (for example, when a terrain id is not found), which is fixed by the following changes:

  1. Restart redrawing of the full UI stack when a debug message is shown during a resize or redraw callback. (The user can ignore the debug message if it occurs every redraw, so there will not be an infinite loop)
  2. Disabled clipping when displaying debug messages to avoid undesired clipping, and restore the SDL clipping rectangle when returning from a debug message popup, so terrain graphics are not drawn outside the clipped area. (Previously, the clipping is somehow reset after displaying debug messages but not restored before returning, so terrain graphics are drawn outside the clipped area and not cleared until the window is resized or game is restarted.)
  3. Frame buffer is invalidated before displaying debug messages so the previous redrawn area is properly overwritten.

Testing

For the first glitch, use the configuration posted in #56064 (other testers may need to adjust the font size to make the active borderless window smaller than the screen), and alt-tab out and back. Before this change sometimes the undrawn edge region contains random pixels (11 out of 20 times when I tested), and after this change the random pixels no longer appear (0 out of 20 times when I tested).

For the second glitch, add a debugmsg call to the redraw callback of the terrain UI and trigger the debug message. Before this fix, if the window has undrawn area below, terrain would be drawn there and not cleared. After this fix, the undrawn area is kept black. I also tested triggering debug messages in the resize and redraw callbacks of the terrain, overmap, and diary UIs, and they were all redrawn correctly after closing the debug message.

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Mar 19, 2022
@NetSysFire NetSysFire added SDL: Tiles / Sound Tiles visual interface and sounds. <Bugfix> This is a fix for a bug (or closes open issue) labels Mar 19, 2022
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Mar 19, 2022
@remd
Copy link
Contributor

remd commented Mar 19, 2022

Unfortunately the issue still persists @Qrox:
image

It occurred after experiencing a debug error popup and closing/ignoring the error.

  • OS: Windows
    • OS Version: 10.0.19043.1586 (21H1)
  • Game Version: 0.F-6791-g3361b06159 [64-bit]
  • Graphics Version: Tiles
  • Game Language: System language []
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food],
    No Fungal Growth [no_fungal_growth],
    Bionic Professions [package_bionic_professions],
    SpeedyDex [speedydex],
    Stats Through Kills [stats_through_kills],
    Stats Through Skills [StatsThroughSkills]
    ]

@remd
Copy link
Contributor

remd commented Mar 19, 2022

I don't think I alt-tabbed at all during this testing session (it was about 5-10 minutes of gameplay, long enough to get to a city from evac shelter and trigger a debug popup) so that aspect of the original bug report may be misleading. Sorry about that.

@Qrox
Copy link
Contributor Author

Qrox commented Mar 19, 2022

Well, in my test I didn't see any stuck graphics when closing a debug error popup. Could you post a screenshot before closing the debug error popup and returning to main menu so I can compare these screenshots?

@remd
Copy link
Contributor

remd commented Mar 19, 2022

The stuck pixels don't appear until the tiles render again after closing the debug popup.

Popup:
image

Immediately after:
image

Main menu:
image

@Qrox
Copy link
Contributor Author

Qrox commented Mar 20, 2022

Popup:

The debug error popup does not hide the sidebar in this image, which is weird.

Immediately after:

Based on my understanding of the code the tile graphics should have the same height as the sidebar, but in this image the tile graphics are taller than the sidebar.

Could you post config/debug.log so I see the stack trace of the error in the first image?

@remd
Copy link
Contributor

remd commented Mar 20, 2022

I don't think I see any additional information. Is there something I can do to increase logging verbosity?

-----------------------------------------
14:49:50.385 : Starting log.
14:49:50.385 INFO : Cataclysm DDA version 0.F-6791-g3361b06159
14:49:50.385 INFO : [main] C locale set to C
14:49:50.385 INFO : [main] C++ locale set to C
14:49:50.385 INFO : SDL version used during compile is 2.0.20
14:49:50.385 INFO : SDL version used during linking and in runtime is 2.0.20
14:49:50.436 INFO : Number of render drivers on your system: 5
14:49:50.436 INFO : Render driver: 0/direct3d
14:49:50.436 INFO : Render driver: 1/direct3d11
14:49:50.436 INFO : Render driver: 2/opengl
14:49:50.436 INFO : Render driver: 3/opengles2
14:49:50.436 INFO : Render driver: 4/software
14:49:50.441 INFO : [options] C locale set to C
14:49:50.441 INFO : [options] C++ locale set to C
14:49:50.441 INFO : Setting language to: 'en'
14:49:50.441 INFO : [i18n] Scanning core translations from lang/mo/
14:49:50.441 INFO : [i18n] Scanning mod translations from ./mods/
14:49:50.442 WARNING : opendir [./mods/] failed with "No such process".
14:49:50.601 INFO : Active renderer: 1/direct3d11
14:49:50.685 INFO : USE_COLOR_MODULATED_TEXTURES is set to 0
14:49:51.026 INFO : Setting language to: 'en'
14:49:51.218 WARNING : opendir [./mods/] failed with "No such process".
14:50:01.514 ERROR : src/assign.h:49 [void report_strict_violation(const JsonObject&, const string&, const string&)] (json-error)
Json error: data/json/overmap/overmap_terrain/overmap_terrain_nether_monster_corpse.json:30:13: cannot assign explicit value the same as default or inherited value

    "id": "corpse_bowels_tentacle_edge",
    "copy-from": "corpse_bowels_empty_edge",
    "color":
            ^
             "red",
    "sym": "E"
  },

14:50:02.628 ERROR : src/assign.h:49 [void report_strict_violation(const JsonObject&, const string&, const string&)] (json-error)
Json error: data/json/overmap/overmap_terrain/overmap_terrain_nether_monster_corpse.json:59:13: cannot assign explicit value the same as default or inherited value

    "id": "corpse_neck",
    "copy-from": "corpse_bowels_empty_edge",
    "color":
            ^
             "red",
    "sym": "N"
  },

14:50:03.128 ERROR : src/assign.h:49 [void report_strict_violation(const JsonObject&, const string&, const string&)] (json-error)
Json error: data/json/overmap/overmap_terrain/overmap_terrain_nether_monster_corpse.json:66:13: cannot assign explicit value the same as default or inherited value

    "id": "corpse_neck_center",
    "copy-from": "corpse_bowels_empty_edge",
    "color":
            ^
             "red",
    "sym": "N"
  },

14:50:03.163 ERROR : src/assign.h:49 [void report_strict_violation(const JsonObject&, const string&, const string&)] (json-error)
Json error: data/json/overmap/overmap_terrain/overmap_terrain_nether_monster_corpse.json:73:13: cannot assign explicit value the same as default or inherited value

    "id": "corpse_head_neck_l",
    "copy-from": "corpse_bowels_empty_edge",
    "color":
            ^
             "red",
    "sym": "H"
  },

14:50:03.194 ERROR : src/assign.h:49 [void report_strict_violation(const JsonObject&, const string&, const string&)] (json-error)
Json error: data/json/overmap/overmap_terrain/overmap_terrain_nether_monster_corpse.json:80:13: cannot assign explicit value the same as default or inherited value

    "id": "corpse_head_neck_r",
    "copy-from": "corpse_bowels_empty_edge",
    "color":
            ^
             "red",
    "sym": "H"
  },

14:50:03.228 ERROR : src/assign.h:49 [void report_strict_violation(const JsonObject&, const string&, const string&)] (json-error)
Json error: data/json/overmap/overmap_terrain/overmap_terrain_nether_monster_corpse.json:87:13: cannot assign explicit value the same as default or inherited value

    "id": "corpse_head_neck_center",
    "copy-from": "corpse_bowels_empty_edge",
    "color":
            ^
             "red",
    "sym": "H"
  },

14:50:03.261 ERROR : src/assign.h:49 [void report_strict_violation(const JsonObject&, const string&, const string&)] (json-error)
Json error: data/json/overmap/overmap_terrain/overmap_terrain_nether_monster_corpse.json:94:13: cannot assign explicit value the same as default or inherited value

    "id": "corpse_head",
    "copy-from": "corpse_bowels_empty_edge",
    "color":
            ^
             "red",
    "sym": "H"
  },

14:50:03.293 ERROR : src/assign.h:49 [void report_strict_violation(const JsonObject&, const string&, const string&)] (json-error)
Json error: data/json/overmap/overmap_terrain/overmap_terrain_nether_monster_corpse.json:101:13: cannot assign explicit value the same as default or inherited value

    "id": "corpse_head_edge",
    "copy-from": "corpse_bowels_empty_edge",
    "color":
            ^
             "red",
    "sym": "H"
  },

14:50:03.326 ERROR : src/assign.h:49 [void report_strict_violation(const JsonObject&, const string&, const string&)] (json-error)
Json error: data/json/overmap/overmap_terrain/overmap_terrain_nether_monster_corpse.json:108:13: cannot assign explicit value the same as default or inherited value

    "id": "corpse_head_fin",
    "copy-from": "corpse_bowels_empty_edge",
    "color":
            ^
             "red",
    "sym": "H"
  },

14:50:03.359 ERROR : src/assign.h:49 [void report_strict_violation(const JsonObject&, const string&, const string&)] (json-error)
Json error: data/json/overmap/overmap_terrain/overmap_terrain_nether_monster_corpse.json:115:13: cannot assign explicit value the same as default or inherited value

    "id": "corpse_head_lcorner",
    "copy-from": "corpse_bowels_empty_edge",
    "color":
            ^
             "red",
    "sym": "H"
  },

14:50:03.393 ERROR : src/assign.h:49 [void report_strict_violation(const JsonObject&, const string&, const string&)] (json-error)
Json error: data/json/overmap/overmap_terrain/overmap_terrain_nether_monster_corpse.json:122:13: cannot assign explicit value the same as default or inherited value

    "id": "corpse_head_rcorner",
    "copy-from": "corpse_bowels_empty_edge",
    "color":
            ^
             "red",
    "sym": "H"
  },

14:50:05.428 WARNING : opendir [./save/Patton/mods] failed with "No such process".
14:50:05.642 INFO : src/mod_tracker.h:64: Tried check if 'FakeSpecial_s_gas' had a duplicate, but type 'overmap_special' does not track object sources
14:50:13.321 INFO : Loaded tileset: Chibi_Ultica
14:50:16.060 INFO : Loaded tileset: Chibi_Ultica
14:54:43.412 ERROR : src/item_factory.cpp:2167 [const itype* Item_factory::find_template(const itype_id&) const] Missing item definition: fireplace_log
14:59:25.636 : Log shutdown.
-----------------------------------------

@Qrox
Copy link
Contributor Author

Qrox commented Mar 20, 2022

I think you need to define BACKTRACE when compiling (And define LIBBACKTRACE and use the library at https://github.com/Qrox/libbacktrace/releases if you are compiling using MinGW)

@remd
Copy link
Contributor

remd commented Mar 20, 2022

OK. It may take me some time to get that set up correctly.

I'm compiling through MSYS2 with this make command:

make -j$((`nproc`+0)) CCACHE=1 RELEASE=1 MSYS2=1 DYNAMIC_LINKING=1 SDL=1 TILES=1 SOUND=1 LOCALIZE=1 LANGUAGES=all LINTJSON=0 ASTYLE=0 RUNTESTS=0

I was following the instructions at https://github.com/CleverRaven/Cataclysm-DDA/blob/178dbc825fb8c3b6bf3ae2bb1feb003b9c97003c/doc/COMPILING/COMPILING-MSYS.md which doesn't seem to go into the details about linking the libbacktrace, probably because it's not always necessary.

@Qrox
Copy link
Contributor Author

Qrox commented Mar 20, 2022

Unless I missed something, you just extract the zipped files to the usual library path and compile with LIBBACKTRACE=1 defined. .github/workflows/release.yml also has an example of using libbacktrace.

@remd
Copy link
Contributor

remd commented Mar 22, 2022

usual library path

Would that be something like C:\dev\msys64\usr\lib?

@Qrox
Copy link
Contributor Author

Qrox commented Mar 22, 2022

I'm using MinGW-w64 so I have no idea what the library path of MSYS2 is. Try it out maybe?

Or you can see if you can reproduce the stuck graphics with the official release, which should already be compiled with stack trace on, and post the stack trace of the debug message that leads to the stuck graphics.

@remd
Copy link
Contributor

remd commented Mar 22, 2022

Since MSYS2 includes mingw64 I assumed you had encountered this. The solution was to unzip libbacktrace to C:\dev\msys64\mingw64.

15:41:15.303 : Starting log.
15:41:15.303 INFO : Cataclysm DDA version 0.F-6791-g3361b06159
15:41:15.303 INFO : [main] C locale set to C
15:41:15.303 INFO : [main] C++ locale set to C
15:41:15.303 INFO : SDL version used during compile is 2.0.20
15:41:15.303 INFO : SDL version used during linking and in runtime is 2.0.20
15:41:15.325 INFO : Number of render drivers on your system: 5
15:41:15.325 INFO : Render driver: 0/direct3d
15:41:15.325 INFO : Render driver: 1/direct3d11
15:41:15.325 INFO : Render driver: 2/opengl
15:41:15.325 INFO : Render driver: 3/opengles2
15:41:15.325 INFO : Render driver: 4/software
15:41:15.328 INFO : [options] C locale set to C
15:41:15.328 INFO : [options] C++ locale set to C
15:41:15.328 INFO : Setting language to: 'en'
15:41:15.328 INFO : [i18n] Scanning core translations from lang/mo/
15:41:15.328 INFO : [i18n] Scanning mod translations from ./mods/
15:41:15.329 WARNING : opendir [./mods/] failed with "No such process".
15:41:15.474 INFO : Active renderer: 1/direct3d11
15:41:15.558 INFO : USE_COLOR_MODULATED_TEXTURES is set to 0
15:41:15.648 INFO : Setting language to: 'en'
15:41:15.746 WARNING : opendir [./mods/] failed with "No such process".
15:41:38.423 WARNING : opendir [./save/Patton/mods] failed with "No such process".
15:41:38.672 INFO : src/mod_tracker.h:64: Tried check if 'FakeSpecial_s_gas' had a duplicate, but type 'overmap_special' does not track object sources
15:41:46.285 INFO : Loaded tileset: Chibi_Ultica
15:41:47.979 INFO : Loaded tileset: Chibi_Ultica
15:41:58.784 ERROR : (error message will follow backtrace)
  #0
    (dbghelp: @0x7ff6c67b3f10[cataclysm-tiles.exe+0x1f3f10]), 
    (libbacktrace: debug_write_backtrace(std::ostream&)+0x9e@0x1401f3f10),
    (libbacktrace: 0x1401f3f10    [unknown src]:0    [unknown func]),
  #1
    (dbghelp: @0x7ff6c67b50f0[cataclysm-tiles.exe+0x1f50f0]), 
    (libbacktrace: DebugLog(DebugLevel, DebugClass)+0x20e@0x1401f50f0),
    (libbacktrace: 0x1401f50f0    [unknown src]:0    [unknown func]),
  #2
    (dbghelp: @0x7ff6c67b6150[cataclysm-tiles.exe+0x1f6150]), 
    (libbacktrace: realDebugmsg(char const*, char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x1ac@0x1401f6150),
    (libbacktrace: 0x1401f6150    [unknown src]:0    [unknown func]),
  #3
    (dbghelp: @0x7ff6c6fe3044[cataclysm-tiles.exe+0xa23044]), 
    (libbacktrace: void realDebugmsg<char const*>(char const*, char const*, char const*, char const*, char const*&&)+0x94@0x140a23044),
    (libbacktrace: 0x140a23044    [unknown src]:0    [unknown func]),
  #4
    (dbghelp: @0x7ff6c69dd4a2[cataclysm-tiles.exe+0x41d4a2]), 
    (libbacktrace: Item_factory::find_template(string_id<itype> const&) const+0x1a2@0x14041d4a2),
    (libbacktrace: 0x14041d4a2    [unknown src]:0    [unknown func]),
  #5
    (dbghelp: @0x7ff6c69a5a35[cataclysm-tiles.exe+0x3e5a35]), 
    (libbacktrace: item::item(string_id<itype> const&, time_point, int)+0x1b@0x1403e5a35),
    (libbacktrace: 0x1403e5a35    [unknown src]:0    [unknown func]),
  #6
    (dbghelp: @0x7ff6c66ba7c8[cataclysm-tiles.exe+0xfa7c8]), 
    (libbacktrace: cata_tiles::draw_from_id_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, TILE_CATEGORY, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, tripoint const&, int, int, lit_level, bool, int&, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x6dc@0x1400fa7c8),
    (libbacktrace: 0x1400fa7c8    [unknown src]:0    [unknown func]),
  #7
    (dbghelp: @0x7ff6c66bf5b7[cataclysm-tiles.exe+0xff5b7]), 
    (libbacktrace: cata_tiles::draw_field_or_item(tripoint const&, lit_level, int&, bool const (&) [5])+0xa97@0x1400ff5b7),
    (libbacktrace: 0x1400ff5b7    [unknown src]:0    [unknown func]),
  #8
    (dbghelp: @0x7ff6c66c184d[cataclysm-tiles.exe+0x10184d]), 
    (libbacktrace: cata_tiles::draw(point const&, tripoint const&, int, int, std::multimap<point, formatted_text, std::less<point>, std::allocator<std::pair<point const, formatted_text> > >&, std::pair<SDL_BlendMode, std::multimap<point, SDL_Color, std::less<point>, std::allocator<std::pair<point const, SDL_Color> > > >&)+0x1bf7@0x14010184d),
    (libbacktrace: 0x14010184d    [unknown src]:0    [unknown func]),
  #9
    (dbghelp: @0x7ff6c6e7ea58[cataclysm-tiles.exe+0x8bea58]), 
    (libbacktrace: cata_cursesport::curses_drawwindow(catacurses::window const&)+0x139@0x1408bea58),
    (libbacktrace: 0x1408bea58    [unknown src]:0    [unknown func]),
  #10
    (dbghelp: @0x7ff6c688fc21[cataclysm-tiles.exe+0x2cfc21]), 
    (libbacktrace: game::draw()+0x12b@0x1402cfc21),
    (libbacktrace: 0x1402cfc21    [unknown src]:0    [unknown func]),
  #11
    (dbghelp: @0x7ff6c6ef9fe9[cataclysm-tiles.exe+0x939fe9]), 
    (libbacktrace: ui_adaptor::redraw_invalidated()+0x16d@0x140939fe9),
    (libbacktrace: 0x140939fe9    [unknown src]:0    [unknown func]),
  #12
    (dbghelp: @0x7ff6c67fafe6[cataclysm-tiles.exe+0x23afe6]), 
    (libbacktrace: do_turn()+0x5ec@0x14023afe6),
    (libbacktrace: 0x14023afe6    [unknown src]:0    [unknown func]),
  #13
    (dbghelp: @0x7ff6c75b1776[cataclysm-tiles.exe+0xff1776]), 
    (libbacktrace: main+0x18f6@0x140ff1776),
    (libbacktrace: 0x140ff1776    [unknown src]:0    [unknown func]),
  #14
    (dbghelp: @0x7ff6c65c13b1[cataclysm-tiles.exe+0x13b1]), 
    (libbacktrace: __tmainCRTStartup+0x231@0x1400013b1),
    (libbacktrace: 0x1400013b1    C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:323    __tmainCRTStartup),
  #15
    (dbghelp: @0x7ff6c65c14c6[cataclysm-tiles.exe+0x14c6]), 
    (libbacktrace: WinMainCRTStartup+0x16@0x1400014c6),
    (libbacktrace: 0x1400014c6    C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:178    WinMainCRTStartup),
  #16
    (dbghelp: BaseThreadInitThunk+0x14@0x7ffc2fb27034[KERNEL32.DLL+0x17034]), 
    (backtrace_syminfo failed: errno = -1, msg = no symbol table in PE/COFF executable),
    (backtrace_pcinfo failed: errno = -1, msg = no debug info in PE/COFF executable),
  #17
    (dbghelp: RtlUserThreadStart+0x21@0x7ffc30502651[ntdll.dll+0x52651]), 
    (backtrace_syminfo failed: errno = -1, msg = no symbol table in PE/COFF executable),
    (backtrace_pcinfo failed: errno = -1, msg = no debug info in PE/COFF executable),
Backtrace emission took 0 seconds.
(continued from above) ERROR : src/item_factory.cpp:2167 [const itype* Item_factory::find_template(const itype_id&) const] Missing item definition: fireplace_log
15:42:07.037 : Log shutdown.

@Qrox
Copy link
Contributor Author

Qrox commented Mar 23, 2022

Thanks, it seems debugmsg is called during a call to ui_adaptor::redraw_invalidated, which is only partially supported, so it may have glitched something out. I'll look into it.

@Qrox Qrox changed the title Fix area outside active borderless window contains glitched graphics when alt-tabbing back Fix glitched graphics in undrawn area of the window Mar 30, 2022
@Qrox
Copy link
Contributor Author

Qrox commented Mar 30, 2022

The new changes should fix the stuck graphics, see the OP for the detail. @remd Please test if it now fixes your issue.

@remd
Copy link
Contributor

remd commented Mar 30, 2022

@Qrox The latest changes fixed the issue for me. 🎉

Thank you! ❤️

@kevingranade kevingranade merged commit 86f487f into CleverRaven:master Apr 2, 2022
@Qrox Qrox deleted the background branch April 17, 2022 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions SDL: Tiles / Sound Tiles visual interface and sounds.
Projects
None yet
4 participants