Opened 6 years ago

Closed 6 years ago

#1657 closed bug (fixed (in master))

Game crashes when mouse clicking squelch menu

Reported by: fizzix Owned by:
Milestone: 3.4.0 Keywords: windows mouse
Cc:

Description

Reported here: http://angband.oook.cz/forum/showthread.php?p=70326

Game crashes when going into squelch menu and clicking anywhere.

Change History (6)

comment:1 Changed 6 years ago by PowerWyrm

Reproduced. It crashes in columns_get_cursor() with a division by zero (colw = 0):

int colw = loc->width / (n + rows_per_page - 1) / rows_per_page;
int cursor = row + rows_per_page * (col - loc->col) / colw;

If I'm not mistaken, it should be:

int colw = loc->width / ((n + rows_per_page - 1) / rows_per_page);

comment:2 Changed 6 years ago by PowerWyrm

In fact, the columns_get_cursor() function is not working at all. Here's the code that should do the job:

static int columns_get_cursor(int row, int col, int n, int top, region *loc)
{
	int w, h, cursor;
        int rows_per_page = loc->page_rows;
        int cols = (n + rows_per_page - 1) / rows_per_page;
	int colw = 23;

	Term_get_size(&w, &h);

	if ((colw * cols) > (w - col))
		colw = (w - col) / cols;

	cursor = (row - loc->row) + rows_per_page * ((col - loc->col) / colw);
	if (cursor < 0) cursor = 0;	/* assert: This should never happen */
	if (cursor >= n) cursor = n - 1;

	return cursor;
}

comment:3 Changed 6 years ago by magnate

  • Resolution set to fixed (in master)
  • Status changed from new to closed

In master as of [177135a]

comment:4 Changed 6 years ago by PowerWyrm

Note that the commit fixes the crash, but the feature isn't fixed at all: clicking with the mouse selects the wrong column. See my comment above for the correct code that fixes everything.

comment:5 Changed 6 years ago by magnate

  • Keywords windows mouse added; Windows, squelch, mouse, crash removed
  • Resolution fixed (in master) deleted
  • Status changed from closed to reopened

comment:6 Changed 6 years ago by magnate

  • Resolution set to fixed (in master)
  • Status changed from reopened to closed

Now in master as [482e77e]

Note: See TracTickets for help on using tickets.