1

So, like many I am going through a tutorial on roguelikes using libtcod in python. http://www.roguebasin.com/index.php?title=Complete_Roguelike_Tutorial,_using_python%2Blibtcod,_part_3

I finally got everything running but I am getting an error on a particular command and I have no idea how to fix it or what is wrong with it exactly. It appears to be working in the tutorial with same command and my code is literally identical as far as I can tell and I am using download links provided by author. I have libtcodpy, dundalk12x12_gs_tc.png, libtcod.dll, and SDL2.dll all in my project folder (copy and pasted in). If you need to see rest of .py then just look at code from tutorial part 3 dungeon generation. It is identical to mine, the only thing I can't see is his libtcodpy folder, but it is his download link. The error is:

C:\Python27\python.exe C:/Users/Chris/PycharmProjects/untitled/KingKong.py
Traceback (most recent call last):
  File "C:/Users/Chris/PycharmProjects/untitled/KingKong.py", line 233, in     <module>
render_all()
  File "C:/Users/Chris/PycharmProjects/untitled/KingKong.py", line 172, in render_all
libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET )
  File "C:\Users\Chris\PycharmProjects\untitled\libtcodpy\__init__.py", line 822, in console_set_char_background
_lib.TCOD_console_set_char_background(con, x, y, col, flag)
WindowsError: exception: access violation reading 0x0000000000640000
24 bits font.
key color : 0 0 0
24bits greyscale font. converting to 32bits

Process finished with exit code 1

The issue is in the renderall function when it is calling the libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET)

def render_all():
global color_dark_wall, color_light_wall
global color_dark_ground, color_light_ground

# Go through all tiles, and set their background color
for y in range(MAP_HEIGHT):
    for x in range(MAP_WIDTH):
        wall = map[x][y].block_sight
        if wall:
            libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET )
        else:
            libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET )

# Draw all objects in the list
for Object in objects:
    Object.draw()

# Blit the contents of "con" to the root console
libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

this is the library function

def console_set_char_background(con, x, y, col, flag=BKGND_SET):
    _lib.TCOD_console_set_char_background(con, x, y, col, flag)

libtcodpy is in my project folder, along with libtcod.dll and SDL2.dll. All are 64 bit, including python and my PyCharm IDE on 64 bit windows 10. Tried 32 bit earlier, won't find SDL2.dll. Already fixed that stuff though on my own. Now I just can't figure out what is erroring and how to rewrite it within the tutorial XX. Sorry first time ever posting on here and did not see exact solution in another thread, had some others regarding SDL issue and 32 vs. 64 bit though.

Please either find me a thoroughly detailed, retard-proof youtube video on how to properly setup libtcodpy in python, or just let me know what I'm messing up.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Chris E
  • 31
  • 5

2 Answers2

1

I get the same issue on Windows 7 64bit, Python 2.7 the dlls are also 64bit.

It only seems to be with the colour code. Remove any colour changes allows it to run.

The error message given (0x0000000000640000 for example) is just the hex code for the colour so the error message codes vary based on the colour used.

I went digging through the code for libtcod in the init.py script it loads the dll and the colour code uses the dll so the error could be in the libtcod.dll or even the sdl2.dll as the sdl2.dll does all the rendering.

Sadly my knowledge is not all that great with python i'm just starting out but if anyone has an answer for me and Chris it would be great.

Salmon85
  • 11
  • 1
0

I have encountered the same problem in my modular version of the code and the answer was simple: you don't have a window created to blit the console to. Make sure you invoke the code for window creation first. I wrapped it in a separate function:

def create_window():
    # set custom font
    libtcod.console_set_custom_font("arial10x10.png", libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    #initialize the main window
    libtcod.console_init_root(SCREEN_W, 
                                SCREEN_H,
                                WINDOW_TITLE + " ver.: " + VERSION,
                                fullscreen = False)
    #limit fps
    libtcod.sys_set_fps(LIMIT_FPS)

I also urge you to check your indentation, since in the code you pasted here, everything is on the same level as render_all() (but your stack trace doesn't support that).

Bit of extra advice: since the dark wall/light wall variables (should be 'lit wall', to be precise but w/e) are declared outside of any function, they're already globals. Setting them as globals inside the function while they're not even declared in it (only used by the function) is completely redundant (mistreatment of variables is the biggest sin in libtcod python roguelike tutorial).

Hope this helps.

tryhard
  • 1
  • 1
  • 1