Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Variants

Reply
 
Thread Tools Display Modes
Old September 9, 2009, 07:28   #1
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 1,124
Donated: $10
will_asher is on a distinguished road
bugfixing trouble again..

A crash bug was reported in DaJAngband recently and I've narrowed it down to a certain part of the earthquake function (a part that I added to the function), but I can't figure out why it's making it crash. It's not a nessesary part of the function so I can just comment it out to fix it, but that seems like a cop out and I'd rather find out why it's making it crash and fix it.
any help?

Code:
/* Examine the quaked region */
for (dy = -r; dy <= r; dy++)
{
for (dx = -r; dx <= r; dx++)
  {
         s16b this_o_idx, next_o_idx = 0;
         int qbreak;
         /* Extract the location */
         yy = cy + dy;
         xx = cx + dx;

         /* Skip unaffected grids */
         if (!map[16+yy-cy][16+xx-cx])
         {

	/* some fragile objects get destroyed even in unaffected grids */
	for (this_o_idx = cave_o_idx[yy][xx]; this_o_idx; this_o_idx = next_o_idx)
	{
		/* get the object */
		object_type *o_ptr = &o_list[this_o_idx];

		/* Get the next object */
		next_o_idx = o_ptr->next_o_idx; /* <<< */
/* this is the line the debugger points to when it crashes */

		/* get odds for object to break (TRUE makes things much less likely to break because it's not a destroyed grid) */
		qbreak = quake_break(o_ptr, TRUE);
		if (artifact_p(o_ptr)) qbreak = 0;

		/* roll for destruction */
		if (rand_int(100) < qbreak)
		{
			/* message */
			if (player_can_see_bold(yy, xx))
			{
				char o_name[80];
				object_desc(o_name, sizeof(o_name), o_ptr, FALSE, 0);
				msg_format("The %s breaks!", o_name);
			}
			delete_object_idx(this_o_idx);
		}
	}
(spacing changed to hopefully make it more readable in the post)


(PS: not sure whether I should post this in the variants section or the development section, but I figured development was for V stuff.)
__________________
Will_Asher
aka LibraryAdventurer

My old variant DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)
will_asher is offline   Reply With Quote
Old September 9, 2009, 07:42   #2
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,692
Donated: $40
Pete Mack is on a distinguished road
object_type *o_ptr = &o_list[this_o_idx];


You are relying on this_o_idx being non-zero, when instead you should be relying on o_ptr being non-null. (!)
Pete Mack is offline   Reply With Quote
Old September 10, 2009, 01:27   #3
zaimoni
Knight
 
zaimoni's Avatar
 
Join Date: Apr 2007
Posts: 590
zaimoni is on a distinguished road
Quote:
Originally Posted by Pete Mack View Post
object_type *o_ptr = &o_list[this_o_idx];


You are relying on this_o_idx being non-zero, when instead you should be relying on o_ptr being non-null. (!)
o_ptr will be non-NULL, as long as o_list is non-NULL (which is handled in initialization). (This code obviously was swiped from V's project_o, which uses the exact same construct).

What it won't automatically be, is valid: that requires verifying that
Code:
(0<this_o_idx) && (this_o_idx<z_info->o_max)
If I recall correctly, the debug mode in recent MSVC can detect out of bounds array accesses (unreliably). Zaiband V3.0.10 has been hardened against this sort of error (all writes to m_idx or o_idx type fields are range-checked in asserts).
__________________
Zaiband: end the "I shouldn't have survived that" experience. V3.0.6 fork on Hg.
Zaiband 3.0.10 ETA Mar. 7 2011 (Yes, schedule slipped. Latest testing indicates not enough assert() calls to allow release.)
Z.C++: pre-alpha C/C++ compiler system (usable preprocessor). Also on Hg. Z.C++ 0.0.10 ETA December 31 2011
zaimoni is offline   Reply With Quote
Old September 10, 2009, 02:37   #4
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 1,124
Donated: $10
will_asher is on a distinguished road
Zaimoni's right. The FOR loop was copied from another place in the code. There are very similar FOR loops in several places in the code which all start with the same line:
Code:
for (this_o_idx = cave_o_idx[yy][xx]; this_o_idx; this_o_idx = next_o_idx)
I just added this line:
Code:
if (!((0 < this_o_idx) && (this_o_idx < z_info->o_max))) break;
right before this line:
Code:
/* Get the next object */
next_o_idx = o_ptr->next_o_idx;
and it didn't crash the next time. thanks Zaimoni!
__________________
Will_Asher
aka LibraryAdventurer

My old variant DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)
will_asher is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Furyband trouble... Tonypantz Variants 6 May 11, 2009 06:20
Interface trouble ofosho Vanilla 0 January 21, 2009 03:19
Trouble Getting Home orbs AAR 3 March 24, 2008 05:01
Angband startup trouble. Zambaku Vanilla 1 January 1, 2008 05:43
trouble staying logged in Velvet Elvis Oook! 2 October 2, 2007 09:05


All times are GMT +1. The time now is 18:23.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.