From ad70442246fc999e9f5c1d04e791b92ec5021fc9 Mon Sep 17 00:00:00 2001 From: James Cowgill Date: Sat, 30 Nov 2024 19:29:16 +0000 Subject: [PATCH] Do not cache atom name if XInternAtom fails If `XInternAtom` is called with `onlyIfExists` set, then it can legitimately return `None`. We should not cache this value because it might change in the future. This bug can sometimes be triggered because we use `getAtom("UTF8_STRING", true)` and `getAtom("UTF8_STRING")`. If the first call caches `None` because the atom didn't exist, then the second call could return `None` instead of creating a new atom like it should. --- src/SFML/Window/Unix/Display.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SFML/Window/Unix/Display.cpp b/src/SFML/Window/Unix/Display.cpp index 5539b0ce3..918382652 100644 --- a/src/SFML/Window/Unix/Display.cpp +++ b/src/SFML/Window/Unix/Display.cpp @@ -129,7 +129,8 @@ Atom getAtom(const std::string& name, bool onlyIfExists) const auto display = openDisplay(); const Atom atom = XInternAtom(display.get(), name.c_str(), onlyIfExists ? True : False); - atoms[name] = atom; + if (atom) + atoms[name] = atom; return atom; }