Click on minimap zooming on the Nile can crash the game

Bug #1658593 reported by SirVer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
Fix Released
High
Unassigned

Bug Description

The exception said: [/Users/sirver/Desktop/Programming/cpp/widelands/bzr_repo/src/graphic/render_queue.cc:191] Too many drawn layers. Ran out of z-values.

There are too many objects on screen to be drawn with our current abstraction.

Tags: graphics

Related branches

SirVer (sirver)
Changed in widelands:
status: New → Confirmed
importance: Undecided → High
assignee: nobody → SirVer (sirver)
milestone: none → build20-rc1
GunChleoc (gunchleoc)
tags: added: graphics
Revision history for this message
SirVer (sirver) wrote :

The problem here is the way Widelands draws items. In the old days of software rendering, we drew objects in the z-order that they should appear in, happily overdrawing what was already in the framebuffer. This made the code very intuitive - the last thing drawn was visible, hiding things that were drawn before - but unfortunately in an OpenGL world, that is not how efficient rendering looks.

Now, you give z-values to your vertices which define which color will appear 'above' in the final framebuffer. This allows for efficient reordering to keep context switches to a minimum.

To keep the old way Widelands drawing code was structured, I abstracted this out in the OpenGL branch by having a RenderQueue that increases the z-value for each rendered object. Unfortunately, OpenGL only offers 16bit of unique z-values. So there was a theoretical limit that we could basically never hit without zooming.

Now with zooming though, we can hit this in extreme circumstances: If the monitor resolution is huge and the zoom is large, we might draw more than 2^16 objects and run out of z-values. This for example happens in the editor when build help is enabled.

There are right ways and easy ways of fixing the issue now:

right way: Restructure the rendering to be aware of the z-layers and explicitly pass the z-values into the drawing code. For example all build help icons could be drawn with the same z-value, since they can never overlap. This would be quite a bit of work, especially for making it correctly work for watch windows as well. Not going to do that anytime soon.

wrong way: Ignore z-values when we run out of them, and just use the biggest one for everything after. I tried this and it did not work: the UI would then all have the same z-value (max), since it is drawn after the mapview. This leads to disappearing buttons, disappearing minimap and so on. However, I do something along those lines if we run out of z-values: I ignore them, leading to UI elements being drawn below build help in these cases. That sucks, but is better than crashing the game and as said, the resolutions must be extreme.

easy way/workaround: Limit the zoom, so that we never run out of z-values. This is what I did in the attached branch: I limited the zoom for animation to also be 4.x (the same as it is for user-controlled zoom). On my monitor at fullscreen (3440x1400 pixels) at maximum zoom, this requires 51302 z-values (screenshot attached). This means that (effective) screen resolutions must only get a bit bigger for this to be a problem again. Screen resolutions have been stagnant for a while, so fingers-crossed that this is sufficient.

SirVer (sirver)
Changed in widelands:
status: Confirmed → In Progress
Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Good idea, same on my side: zomming out will slow down the game to a crawl.
Will try to check this later.

SirVer (sirver)
Changed in widelands:
status: In Progress → Fix Committed
assignee: SirVer (sirver) → nobody
Revision history for this message
GunChleoc (gunchleoc) wrote :

Fixed in build20-rc1

Changed in widelands:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.