View Single Post
Old July 19, 2017, 11:06   #3
AndreyB
Scout
 
Join Date: May 2017
Location: Russia
Posts: 26
AndreyB is on a distinguished road
Sometimes two code snippets can tell more than a thousand words.

Code:
[user@computer src]$ cat -n main-sdl.c | sed -n '3380,3419p'
  3380	/**
  3381	 * Create the windows
  3382	 * Called sometime after load_prefs()
  3383	 */
  3384	static void init_windows(void)
  3385	{
  3386		int i;
  3387	
  3388		for (i = 0; i < ANGBAND_TERM_MAX; i++) {
  3389			term_window *win = &windows[i];
  3390			
  3391			/* Only bother with visible windows */
  3392			if (win->visible) {
  3393				/* Don't crowd out the status bar... */
  3394				if (win->top < StatusHeight) win->top = StatusHeight;
  3395	
  3396				/* Invalidate the gfx surface */
  3397				if (win->tiles) {
  3398					SDL_FreeSurface(win->tiles);
  3399					win->tiles = NULL;
  3400				}
  3401				if (win->onebyone) {
  3402					SDL_FreeSurface(win->onebyone);
  3403					win->onebyone = NULL;
  3404				}
  3405	
  3406				/* This will set up the window correctly */
  3407				ResizeWin(win, win->width, win->height);
  3408			} else {
  3409				/* Doesn't exist */
  3410				angband_term[i] = NULL;
  3411			}
  3412			
  3413			/* Term 0 is at the top */
  3414			Zorder[i] = ANGBAND_TERM_MAX - i - 1;
  3415		}
  3416	
  3417		/* Good to go... */
  3418		Term_activate(term_screen);
  3419	}
Code:
[user@computer src]$ grep -B17 -A14 -rne 'win->tiles = win->onebyone'
main-sdl.c-3123-static void Term_view_map_sdl(term *t)
main-sdl.c-3124-{
main-sdl.c-3125-	SDL_Surface *fulltiles;
main-sdl.c-3126-	/* Get the right window */
main-sdl.c-3127-	term_window *win = (term_window*)(t->data);
main-sdl.c-3128-
main-sdl.c-3129-	/* First time a pict is requested we load the tileset in */
main-sdl.c-3130-	if (!win->tiles)
main-sdl.c-3131-		sdl_BuildTileset(win);
main-sdl.c-3132-
main-sdl.c-3133-	/* Override large tiles with small ones for the map view */
main-sdl.c-3134-	if (win->onebyone) {
main-sdl.c-3135-		/* Save screen so we can load it again after the tile image
main-sdl.c-3136-		 * is restored */
main-sdl.c-3137-		screen_save();
main-sdl.c-3138-
main-sdl.c-3139-		fulltiles = win->tiles;
main-sdl.c:3140:		win->tiles = win->onebyone;
main-sdl.c-3141-	}
main-sdl.c-3142-
main-sdl.c-3143-	t->view_map_hook = NULL;
main-sdl.c-3144-	do_cmd_view_map();
main-sdl.c-3145-	t->view_map_hook = Term_view_map_sdl;
main-sdl.c-3146-
main-sdl.c-3147-	if (win->onebyone) {
main-sdl.c-3148-		win->tiles = fulltiles;
main-sdl.c-3149-
main-sdl.c-3150-		/* Load screen with the correct tiles - the screen load in the
main-sdl.c-3151-		 * view map command was still using the image with small tiles */
main-sdl.c-3152-		screen_load();
main-sdl.c-3153-	}
main-sdl.c-3154-}
[user@computer src]$
I wonder how many times in my career I will make the same bug.
Edit: valgrind is awesome. It's the biggest timesaver people invented since the invention of the wheel.

Last edited by AndreyB; July 19, 2017 at 12:47.
AndreyB is offline   Reply With Quote