GNU bug report logs - #62392
frame-monitor-attributes fails to calculate mm-size for the monitor

Previous Next

Package: emacs;

Reported by: tomasralph2000 <at> gmail.com

Date: Wed, 22 Mar 2023 20:43:01 UTC

Severity: normal

Tags: moreinfo

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 62392 in the body.
You can then email your comments to 62392 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#62392; Package emacs. (Wed, 22 Mar 2023 20:43:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to tomasralph2000 <at> gmail.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 22 Mar 2023 20:43:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: tomasralph2000 <at> gmail.com
To: bug-gnu-emacs <at> gnu.org
Subject: frame-monitor-attributes fails to calculate mm-size for  the monitor
Date: Wed, 22 Mar 2023 19:35:21 +0000
[Message part 1 (text/plain, inline)]
Whenever I try to run tetris, or snake, or pong, I get "arithmetic overflow error". After digging a bit, I found where the issue lies. This function:

 (defun gamegrid-calculate-glyph-size ()
 "Calculate appropriate glyph size in pixels based on display resolution.
 Return a multiple of 8 no less than 16."
 (let ((atts (frame-monitor-attributes))
 y-pitch)
 (setq y-pitch (cond
 (atts
 (/ (nth 4 (assq 'geometry atts))
 (nth 2 (assq 'mm-size atts))
 (or (cdr (assq 'scale-factor atts)) 1.0)))
 ((and (display-pixel-height) (display-mm-height))
 (/ (display-pixel-height) (float (display-mm-height))))))
 (if y-pitch
 (let* ((pixels (* y-pitch gamegrid-glyph-height-mm))
 (rounded (* (floor (/ (+ pixels 4) 8)) 8)))
 (max 16 rounded))
 16)))

Is the one causing the error. Where in particular? This section:

 (/ (nth 4 (assq 'geometry atts))
 (nth 2 (assq 'mm-size atts))

What's the issue here? `(assq 'mm-size atts)` returns 0. For some reason, emacs can't seem to get my monitor size in milimeters. I have tried this on two different laptops, they both return proper values. This is happening on my desktop, where it fails.

I am using Wayland (with Hyprland) and the PGTK version of emacs, which likely has something to do with this. This is what `frame-monitor-attributes` returns for me:

 ((name . "HDMI") (geometry 0 0 1920 1080) (workarea 0 0 1920 1080) (mm-size 0 0) (scale-factor . 1.0) (frames #<frame *scratch* - GNU Emacs at Rainbow 0x55799b79aa48> #<frame 0x55799d4561e0>) (source . "Gdk"))

As you can see, the `mm-size` is 0, so emacs divides by zero. Amazingly, this is not what causes the error, the variable simply gets set to infinity. The error comes later, when it tries to multiply by infinity. Oh lord.

This is what emacs outputs on my laptop for the same `frame-monitor-attributes`. Note that my laptop runs the exact same setup, it also runs Hyprland, it also runs emacs with PGTK, it uses the same config for everything since I have the same dotifles repo cloned in both systems:

 ((name . "0x0335") (geometry 0 0 1366 768) (workarea 0 0 1366 768) (mm-size 310 170) (scale-factor . 1.0) (frames #<frame *scratch* - GNU Emacs at T430 0x55c4c1cdad20> #<frame 0x55c4c356b7e0>) (source . "Gdk"))

This time, the `mm-size` gets properly calculated.

So something is funky with `frame-monitor-attributes`. Any direction on
how I can further debug this would be appreciated.
In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.37, cairo version 1.17.8) of 2023-03-21 built on Rainbow
Repository revision: 42fba8f36b19536964d6deb6a34f3fd1c02b43dd
Repository branch: makepkg
System Description: Arch Linux

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
 --with-modules --without-libotf --without-m17n-flt --without-gconf
 --with-native-compilation=yes --with-native-compilation=aot
 --with-xinput2 --with-pgtk --without-xaw3d --with-sound=alsa
 --with-tree-sitter --without-gpm --without-compress-install
 '--program-transform-name=s/([ec]tags)/1.emacs/'
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions
 -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security
 -fstack-clash-protection -fcf-protection'
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PGTK
PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS
TREE_SITTER WEBP XIM GTK3 ZLIB

Important settings:
 value of $LANG: en_US.UTF-8
 locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
 which-key-mode: t
 recentf-mode: t
 global-git-commit-mode: t
 magit-auto-revert-mode: t
 shell-dirtrack-mode: t
 override-global-mode: t
 vertico-mouse-mode: t
 vertico-mode: t
 corfu-popupinfo-mode: t
 global-corfu-mode: t
 corfu-mode: t
 pixel-scroll-precision-mode: t
 global-display-line-numbers-mode: t
 display-line-numbers-mode: t
 tooltip-mode: t
 global-eldoc-mode: t
 eldoc-mode: t
 show-paren-mode: t
 electric-indent-mode: t
 mouse-wheel-mode: t
 file-name-shadow-mode: t
 global-font-lock-mode: t
 font-lock-mode: t
 blink-cursor-mode: t
 line-number-mode: t
 transient-mark-mode: t
 auto-composition-mode: t
 auto-encryption-mode: t
 auto-compression-mode: t

Load-path shadows:
/home/tralph3/.local/share/emacs/elpa/jsonrpc-1.0.16/jsonrpc hides /usr/share/emacs/30.0.50/lisp/jsonrpc
/home/tralph3/.local/share/emacs/elpa/transient-20230304.1149/transient hides /usr/share/emacs/30.0.50/lisp/transient
/home/tralph3/.local/share/emacs/elpa/use-package-20230203.2004/use-package hides /usr/share/emacs/30.0.50/lisp/use-package/use-package
/home/tralph3/.local/share/emacs/elpa/use-package-20230203.2004/use-package-core hides /usr/share/emacs/30.0.50/lisp/use-package/use-package-core
/home/tralph3/.local/share/emacs/elpa/use-package-20230203.2004/use-package-jump hides /usr/share/emacs/30.0.50/lisp/use-package/use-package-jump
/home/tralph3/.local/share/emacs/elpa/use-package-20230203.2004/use-package-bind-key hides /usr/share/emacs/30.0.50/lisp/use-package/use-package-bind-key
/home/tralph3/.local/share/emacs/elpa/use-package-20230203.2004/use-package-delight hides /usr/share/emacs/30.0.50/lisp/use-package/use-package-delight
/home/tralph3/.local/share/emacs/elpa/use-package-20230203.2004/use-package-diminish hides /usr/share/emacs/30.0.50/lisp/use-package/use-package-diminish
/home/tralph3/.local/share/emacs/elpa/bind-key-20230203.2004/bind-key hides /usr/share/emacs/30.0.50/lisp/use-package/bind-key
/home/tralph3/.local/share/emacs/elpa/use-package-20230203.2004/use-package-lint hides /usr/share/emacs/30.0.50/lisp/use-package/use-package-lint
/home/tralph3/.local/share/emacs/elpa/use-package-20230203.2004/use-package-ensure hides /usr/share/emacs/30.0.50/lisp/use-package/use-package-ensure
/home/tralph3/.local/share/emacs/elpa/project-0.9.8/project hides /usr/share/emacs/30.0.50/lisp/progmodes/project
/home/tralph3/.local/share/emacs/elpa/eglot-20221020.1010/eglot hides /usr/share/emacs/30.0.50/lisp/progmodes/eglot
/home/tralph3/.local/share/emacs/elpa/xref-1.6.2/xref hides /usr/share/emacs/30.0.50/lisp/progmodes/xref

Features:
(shadow sort mail-extr emacsbug rect pong novice shortdoc bug-hunter
help-fns radix-tree cl-print disp-table tetris gamegrid mule-util
magit-bookmark bookmark time eglot array jsonrpc ert pp ewoc debug
backtrace find-func xref flymake-proc flymake project org-faces
org-version org-macs which-key dashboard dashboard-widgets all-the-icons
all-the-icons-faces data-material data-weathericons data-octicons
data-fileicons data-faicons data-alltheicons recentf tree-widget
wid-edit ffap orderless magit-submodule magit-obsolete magit-blame
magit-stash magit-reflog magit-bisect magit-push magit-pull magit-fetch
magit-clone magit-remote magit-commit magit-sequence magit-notes
magit-worktree magit-tag magit-merge magit-branch magit-reset
magit-files magit-refs magit-status magit magit-repos magit-apply
magit-wip magit-log which-func imenu magit-diff smerge-mode diff
diff-mode git-commit log-edit message sendmail yank-media puny dired
dired-loaddefs rfc822 mml mml-sec epa derived epg rfc6068 epg-config
gnus-util time-date mm-decode mm-bodies mm-encode mail-parse rfc2231
rfc2047 rfc2045 mm-util ietf-drums mail-prsvr mailabbrev mail-utils
gmm-utils mailheader pcvs-util add-log magit-core magit-autorevert
autorevert filenotify magit-margin magit-transient magit-process
with-editor shell pcomplete server magit-mode transient magit-git
magit-base magit-section format-spec crm dash edmacro kmacro
use-package-bind-key bind-key easy-mmode vertico-mouse vertico
rust-utils thingatpt rust-mode rust-rustfmt rust-playpen rust-compile
compile text-property-search comint ansi-osc ansi-color rust-cargo
kind-icon svg-lib color svg dom xml corfu-popupinfo corfu compat
compat-29 use-package-ensure use-package-core pixel-scroll cua-base ring
comp comp-cstr warnings icons rx cl-extra help-mode display-line-numbers
pcase bug-hunter-autoloads neotree-autoloads org-bullets-autoloads
which-key-autoloads markdown-mode-autoloads dashboard-autoloads info
package browse-url url url-proxy url-privacy url-expand url-methods
url-history url-cookie generate-lisp-file url-domsuf url-util mailcap
url-handlers url-parse auth-source cl-seq eieio eieio-core cl-macs
password-cache json subr-x map byte-opt gv bytecomp byte-compile
url-vars cl-loaddefs cl-lib rmc iso-transl tooltip cconv eldoc paren
electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/pgtk-win pgtk-win term/common-win pgtk-dnd tool-bar dnd fontset
image regexp-opt fringe tabulated-list replace newcomment text-mode
lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify
dynamic-setting system-font-setting font-render-setting cairo gtk pgtk
lcms2 multi-tty make-network-process native-compile emacs)

Memory information:
((conses 16 319167 94405)
 (symbols 48 21107 3)
 (strings 32 87375 4726)
 (string-bytes 1 3487955)
 (vectors 16 53395)
 (vector-slots 8 1061140 40998)
 (floats 8 774 1186)
 (intervals 56 2980 534)
 (buffers 984 30))
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62392; Package emacs. (Thu, 23 Mar 2023 00:48:02 GMT) Full text and rfc822 format available.

Message #8 received at 62392 <at> debbugs.gnu.org (full text, mbox):

From: Po Lu <luangruo <at> yahoo.com>
To: tomasralph2000 <at> gmail.com
Cc: 62392 <at> debbugs.gnu.org
Subject: Re: bug#62392: frame-monitor-attributes fails to calculate mm-size
 for  the monitor
Date: Thu, 23 Mar 2023 08:47:34 +0800
tomasralph2000 <at> gmail.com writes:

> Is the one causing the error. Where in particular? This section:
>
> (/ (nth 4 (assq 'geometry atts))
> (nth 2 (assq 'mm-size atts))
>
> What's the issue here? `(assq 'mm-size atts)` returns 0. For some reason, emacs can't seem to get my monitor size in milimeters. I have tried
> this on two different laptops, they both return proper values. This is happening on my desktop, where it fails.
>
> I am using Wayland (with Hyprland) and the PGTK version of emacs, which likely has something to do with this. This is what
> `frame-monitor-attributes` returns for me:
>
> ((name . "HDMI") (geometry 0 0 1920 1080) (workarea 0 0 1920 1080) (mm-size 0 0) (scale-factor . 1.0) (frames #<frame *scratch* - GNU Emacs at
> Rainbow 0x55799b79aa48> #<frame 0x55799d4561e0>) (source . "Gdk"))
>
> As you can see, the `mm-size` is 0, so emacs divides by zero. Amazingly, this is not what causes the error, the variable simply gets set to
> infinity. The error comes later, when it tries to multiply by infinity. Oh lord.
>
> This is what emacs outputs on my laptop for the same `frame-monitor-attributes`. Note that my laptop runs the exact same setup, it also runs
> Hyprland, it also runs emacs with PGTK, it uses the same config for everything since I have the same dotifles repo cloned in both systems:
>
> ((name . "0x0335") (geometry 0 0 1366 768) (workarea 0 0 1366 768) (mm-size 310 170) (scale-factor . 1.0) (frames #<frame *scratch* - GNU
> Emacs at T430 0x55c4c1cdad20> #<frame 0x55c4c356b7e0>) (source . "Gdk"))
>
> This time, the `mm-size` gets properly calculated.
>
> So something is funky with `frame-monitor-attributes`. Any direction on
> how I can further debug this would be appreciated.

On the contrary, something is funky with the EDID information from your
monitor, so the Wayland compositor is giving out faulty information.

What is the actual pixel resolution of the monitor connected to the
output named ``HDMI''? If it is indeed 72dpi (or something close), I
think tetris should just use `scale-factor' if available.

Thanks.




Added tag(s) moreinfo. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 12 Sep 2023 00:06:02 GMT) Full text and rfc822 format available.

Reply sent to Stefan Kangas <stefankangas <at> gmail.com>:
You have taken responsibility. (Mon, 23 Oct 2023 20:13:02 GMT) Full text and rfc822 format available.

Notification sent to tomasralph2000 <at> gmail.com:
bug acknowledged by developer. (Mon, 23 Oct 2023 20:13:02 GMT) Full text and rfc822 format available.

Message #15 received at 62392-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Po Lu <luangruo <at> yahoo.com>
Cc: tomasralph2000 <at> gmail.com, 62392-done <at> debbugs.gnu.org
Subject: Re: bug#62392: frame-monitor-attributes fails to calculate mm-size
 for the monitor
Date: Mon, 23 Oct 2023 13:12:06 -0700
Po Lu <luangruo <at> yahoo.com> writes:

> On the contrary, something is funky with the EDID information from your
> monitor, so the Wayland compositor is giving out faulty information.
>
> What is the actual pixel resolution of the monitor connected to the
> output named ``HDMI''? If it is indeed 72dpi (or something close), I
> think tetris should just use `scale-factor' if available.

More information was requested, but none was given within 6 months, so
I'm closing this bug.  If this is still an issue, please reply to this
email (use "Reply to all" in your email client) and we can reopen the
bug report.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 21 Nov 2023 12:24:17 GMT) Full text and rfc822 format available.

This bug report was last modified 128 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.