Bug #15127, was updated on 2009-Jan-26 09:48
Here is a current snapshot of the bug.

Project: LinCityNG
Category: None
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Submitted by: danielsantos
Assigned to : none
Summary: Crash when selecting a location to build water well

Details: Too bad I didn't think to save my game, I was almost at tech level 5 
and hadn't saved. :(

So I seem to be able to reproduce it in a number of ways.  Basically, you zoom 
all the way, scroll all the way up as far as you can in the map, click the  
build water well button and move the mouse around in the upper areas of the 
window (outside of the map area).  This occurs in both 2.0 and current svn 
(r1518)

(gdb) bt
bt
#0  0x00000000004a5bc9 in is_allowed_here (x=-114, y=-17, type=238, msg=0) at 
src/lincity/engine.cpp:158
#1  0x000000000044f75c in GameView::markTile (this=0x9fbcc0, paint...@0x9eced0, 
tile={x = -114, y = -17}) at src/lincity-ng/GameView.cpp:1443
#2  0x00000000004501ff in GameView::draw (this=0x9fbcc0, paint...@0x9eced0) at 
src/lincity-ng/GameView.cpp:1628
#3  0x000000000047135d in Component::drawChild (this=0x9fabd0, chi...@0xe06170, 
paint...@0x9eced0) at src/gui/Component.cpp:66
#4  0x0000000000471404 in Component::draw (this=0x9fabd0, paint...@0x9eced0) at 
src/gui/Component.cpp:83
#5  0x000000000048fb58 in Desktop::draw (this=0x9fabd0, paint...@0x9eced0) at 
src/gui/Desktop.cpp:108
#6  0x000000000045f881 in Game::run (this=0x9f08a0) at 
src/lincity-ng/Game.cpp:238
#7  0x0000000000408a76 in mainLoop () at src/lincity-ng/main.cpp:351
#8  0x000000000040a599 in main (argc=1, argv=0x7fff5aa5d178) at 
src/lincity-ng/main.cpp:492
(gdb) info locals
info locals
group = 41
size = 2
i = 0
j = 0
has_ugw = 0

It looks like it's failing because it wasn't designed to accept invalid x, y 
coordinates.

Follow-Ups:

Date: 2009-Jan-26 23:07
By: jaky_lincity

Comment:
It doesn't crash on my computer either. But the call to HAS_UGWATER on line 158 
tries to access the map.info array outside of its boundaries, if the x and y 
value is outside of the map. Probably this is the cause for the segfault. 
map.info is also accessed for Ports, tips, oremines and parks. It could also 
crash for these buildings. 

Jaky
-------------------------------------------------------

Date: 2009-Jan-26 23:06
By: jaky_lincity

Comment:
It doesn't crash on my computer either. But the call to HAS_UGWATER on line 158 
tries to access the map.info array outside of its boundaries, if the x and y 
value is outside of the map. This is the cause for the segfault. 
map.info is also accessed for Ports, tips, oremines and parks. It could also 
crash for these buildings. 

Jaky
-------------------------------------------------------

Date: 2009-Jan-26 18:55
By: wolfgangb

Comment:
Works fine for me, I can't reproduce the crash here. Strange. Which 
compiler/platform do you use? Do you get the crash with other buildings, too?

As far as I understand the code, the invisible border is required so every 
building is surrounded by tiles. That way you don't need special cases for 
pollution and transport checks.
-------------------------------------------------------

Date: 2009-Jan-26 16:44
By: jaky_lincity

Comment:
Thank you very much for your detailed bug report. But your patch does not cover 
all the cases. We have to take into account the size of the building to prevent 
some part of the building being outside of the map. And the first usable tile 
starts with x=y=1 and the last one is at x=y=98. This is due to an invisible 
one-tile border around the map. I don't know why it exists. Maybe to prevent 
crashes due to off-by-one errors.

We can use the check from MapEdit.cpp line 243 which is used while actually 
building something. Updated patch:

Index: src/lincity/engine.cpp
===================================================================
--- src/lincity/engine.cpp      (revision 1518)
+++ src/lincity/engine.cpp      (working copy)
@@ -108,6 +108,9 @@
     int i,j;
     int has_ugw = 0;

+    if( x + size > WORLD_SIDE_LEN - 1 || y + size > WORLD_SIDE_LEN - 1 || x < 
1 || y < 1 )
+        return false;
+
     switch (group) {
    case GROUP_SOLAR_POWER:
         if (total_money <= 0) {
-------------------------------------------------------

Date: 2009-Jan-26 13:16
By: danielsantos

Comment:
Correction: Basically, you zoom *out* all the way, ...
-------------------------------------------------------

Date: 2009-Jan-26 09:52
By: danielsantos

Comment:
This seems to fix the problem:
Index: src/lincity/engine.cpp
===================================================================
--- src/lincity/engine.cpp      (revision 1518)
+++ src/lincity/engine.cpp      (working copy)
@@ -107,6 +107,9 @@
     int size = main_groups[group].size;
     int i,j;
     int has_ugw = 0;
+
+    if( x < 0 || y < 0 || x >= WORLD_SIDE_LEN || y >= WORLD_SIDE_LEN )
+        return 0;

     switch (group) {
     case GROUP_SOLAR_POWER:

-------------------------------------------------------

For detailed info, follow this link:
http://developer.berlios.de/bugs/?func=detailbug&bug_id=15127&group_id=2929
_______________________________________________
Lincity-ng-devel mailing list
Lincity-ng-devel@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/lincity-ng-devel

Reply via email to