theme definition bug

Discussion of all aspects of the game engine, including development of new and existing features.

Moderator: Forum Moderators

Post Reply
Yogibear
Retired Developer
Posts: 1086
Joined: September 16th, 2005, 5:44 am
Location: Hamburg, Germany

theme definition bug

Post by Yogibear »

During experimenting with themes, i found something i consider to be a bug:

If you define a panel at the bottom of the window, set yanchor to "fixed" and start the application in a window, it crashes without error message.

The reason for this is found in theme::object::location where it says:
relative_loc_.h = minimum<int>(relative_loc_.h, screen.h - relative_loc_.y);

This might result in being zero and leads to a "division by zero"-error in scale_surface(...) later on, which gets not caught.

So i suggest to either prevent h from becoming zero or check zero values in scale_surface (or even in the macro fxpdiv). Of course, this applies to the width as well.
Smart persons learn out of their mistakes, wise persons learn out of others mistakes!
ott
Inactive Developer
Posts: 838
Joined: September 28th, 2004, 10:20 am

Post by ott »

[Moved to a more appropriate forum.]

This problem is endemic throughout the code. Basically, there is an assumption that the values for height/width/x/y are benign. We could just slap a wassert(h>0 && w >0) into scale_surface(), but that would simply crash with an assertion instead of division by 0, so no real progress there.

There are 15 different places that scale_surface() is used in the code. I started looking at ways to clean this up, but saw no clean way to do so. It looks like we will have to trace where each w/x/y/h passed as an argument to scale_surface() is initialised, and ensure sanity checking at those points. We need to make sure that the preference values for screen resolution are reasonable (ie. x != 0 and y != 0, since some SDL implementations may be OK with asking for a 0x0 surface), and that the attributes of rectangles specified in theme files are reasonable.
This quote is not attributable to Antoine de Saint-Exupéry.
Post Reply