Author Topic: Strange Display Errors  (Read 9919 times)

Shaggy

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
  • (╯°□°)╯︵ ┻━┻ <( !@#$ THIS, I'M OUT. )
    • View Profile
    • Not Quite ADoM
    • Email
Strange Display Errors
« on: November 05, 2012, 11:31:31 AM »
Somehow I keep getting an error from trying to print over the edge of the console, but I can't see how. There's only two main rendering codes, one that renders the 'borders' of the interface, and one that renders everything else. Here's the code, I don't know what's causing it.

Relevant Constants
Code: [Select]
#actual size of the window
SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50
 
#coordinates relevant to the GUI
MAP_X_OFFSET = 1
MAP_Y_OFFSET = 5

#size of the map
MAP_WIDTH = 67
MAP_HEIGHT = 43

and here's the two rendering routines
Code: [Select]
   
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute
 
    if fov_recompute:
        #recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
 
        #go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    #if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_put_char_ex(con, x+MAP_X_OFFSET, y+MAP_Y_OFFSET, chr(176), color_dark_wall, libtcod.black)
                        else:
                            libtcod.console_put_char_ex(con, x+MAP_X_OFFSET, y+MAP_Y_OFFSET, '.', color_dark_ground, libtcod.black)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_put_char_ex(con, x+MAP_X_OFFSET, y+MAP_Y_OFFSET, chr(176), color_light_wall, libtcod.black)
                    else:
                        libtcod.console_put_char_ex(con, x+MAP_X_OFFSET, y+MAP_Y_OFFSET,  '.', color_light_ground, libtcod.black)
                    #since it's visible, explore it
                    map[x][y].explored = True
 
    #draw all objects in the list, except the player. we want it to
    #always appear over all other objects! so it's drawn later.
    for object in objects:
        if object != player:
            object.draw()
    player.draw()
 
    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)
 
 
    #prepare to render the GUI panel
    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)
 
    #print the game messages, one line at a time
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1
 
    #show the player's stats
    render_bar(3, 2, BAR_WIDTH, player.fighter.hp, player.fighter.max_hp,
        libtcod.light_red, libtcod.darker_red)
 
    #display names of objects under the mouse
    libtcod.console_set_foreground_color(panel, libtcod.light_gray)
    libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE, get_names_under_mouse())
 
    #blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)

    #render the UI over everything else
    render_UI()

def render_UI():
    global gui
   
    libtcod.console_print_left(gui, 0,4, libtcod.BKGND_SET, '+-------------------------------------------------------------------+----------+')
    libtcod.console_print_left(gui, 0,49, libtcod.BKGND_SET, '+-------------------------------------------------------------------+----------+')
   
    y = 5
   
    while y < 48:
   
        libtcod.console_print_left(gui, 0,y, libtcod.BKGND_SET, '|                                                                   |          |')
        y += 1
   
    libtcod.console_blit(gui, 0, 0, 80, 50, 0, 0, 0, 1, 0)
    libtcod.console_flush()

So at the bottom left, even after the offsets, nothing should be printed outside the console. Yet I'm getting that error returned. It's strange though. Sometimes it works fine and there are no errors, sometimes it doesn't print anything and returns an error, and sometimes it will print the whole GUI and then return an error. The object draw/clear class also has the offset added in, but could never have an x/y value outside of the map of course.
Check out my blog at http://NotQuiteADoM.blogspot.com/ !

kraflab

  • Rogueliker
  • ***
  • Posts: 454
  • Karma: +0/-0
    • View Profile
    • kraflab.com
Re: Strange Display Errors
« Reply #1 on: November 05, 2012, 01:09:28 PM »
I don't know libtcod, so this is just a guess.

Any chance those functions where you use 50, 80 should be using 49, 79?  That is, I don't know if you are putting in size or maximum there.

mendonca

  • Newcomer
  • Posts: 11
  • Karma: +0/-0
    • View Profile
    • A Hundred Heroes - Roguelike Reviews and Ruminations
    • Email
Re: Strange Display Errors
« Reply #2 on: November 05, 2012, 04:20:54 PM »
I could well be wrong, but I am suspicious of those offsets.

How have you defined 'con'? At what size?

Just looking at the code - you seem to be putting things (console_put_char_ex) at up to MAP_WIDTH + offset, but only blitting up to MAP_WIDTH (for example) - at the very least that will mean you can't see all the changes you have made - and if you haven't made 'con' big enough, you could be printing outside this console.

Shaggy

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
  • (╯°□°)╯︵ ┻━┻ <( !@#$ THIS, I'M OUT. )
    • View Profile
    • Not Quite ADoM
    • Email
Re: Strange Display Errors
« Reply #3 on: November 05, 2012, 10:22:11 PM »
I could well be wrong, but I am suspicious of those offsets.

How have you defined 'con'? At what size?

Just looking at the code - you seem to be putting things (console_put_char_ex) at up to MAP_WIDTH + offset, but only blitting up to MAP_WIDTH (for example) - at the very least that will mean you can't see all the changes you have made - and if you haven't made 'con' big enough, you could be printing outside this console.

Ahh, you were right! I was adding the offset to the offscreen console, instead I should've been adding it when I flushed it to the main screen.

Changed this;
Code: [Select]
    #blit the contents of "con" to the root console
    #libtcod.console_blit(srcConsole, srcX, srcY, scrWidth, scrHeight, trgtConsole, trgtX, trgtY)
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)

to this;
Code: [Select]
    #blit the contents of "con" to the root console
    #libtcod.console_blit(srcConsole, srcX, srcY, scrWidth, scrHeight, trgtConsole, trgtX, trgtY)
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, MAP_X_OFFSET, MAP_Y_OFFSET)
Check out my blog at http://NotQuiteADoM.blogspot.com/ !

careyjennifer

  • Newcomer
  • Posts: 1
  • Karma: +0/-0
    • MSN Messenger - ambrljones@yahoo.com
    • AOL Instant Messenger - careyjennifer
    • Yahoo Instant Messenger - careyjennifer
    • View Profile
    • Email
Re: Strange Display Errors
« Reply #4 on: November 17, 2012, 04:36:27 AM »
I could well be wrong, but I am suspicious of those offsets.

How have you defined 'con'? At what size?

Just looking at the code - you seem to be putting things (console_put_char_ex) at up to MAP_WIDTH + offset, but only blitting up to MAP_WIDTH (for example) - at the very least that will mean you can't see all the changes you have made - and if you haven't made 'con' big enough, you could be printing outside this console.

Ahh, you were right! I was adding the offset to the offscreen console, instead I should've been adding it when I flushed it to the main screen.

Changed this;
Code: [Select]
    #blit the contents of "con" to the root console
    #libtcod.console_blit(srcConsole, srcX, srcY, scrWidth, scrHeight, trgtConsole, trgtX, trgtY)
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)

to this;
Code: [Select]
    #blit the contents of "con" to the root console
    #libtcod.console_blit(srcConsole, srcX, srcY, scrWidth, scrHeight, trgtConsole, trgtX, trgtY)
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, MAP_X_OFFSET, MAP_Y_OFFSET)



Did you changed the offset? Is it working now?




guest509

  • Guest
Re: Strange Display Errors
« Reply #5 on: November 17, 2012, 10:59:11 AM »
  Magic numbers got you!

Shaggy

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
  • (╯°□°)╯︵ ┻━┻ <( !@#$ THIS, I'M OUT. )
    • View Profile
    • Not Quite ADoM
    • Email
Re: Strange Display Errors
« Reply #6 on: November 19, 2012, 12:40:28 AM »
Did you changed the offset? Is it working now?

It's working, and I didn't need to change the offset. I just wasn't rendering it to the main console in the correct spot  ::)
Check out my blog at http://NotQuiteADoM.blogspot.com/ !