overdev / raylib-py

A Python binding for the great C library raylib.
Other
185 stars 20 forks source link

Calling `begin_drawing` causes a segmentation fault #6

Closed carlsmith closed 5 years ago

carlsmith commented 5 years ago

I just tried running this code:

import raylibpy
raylibpy.begin_drawing()
raylibpy.end_drawing()

It exited with Segmentation fault: 11 (on macOS 10.14.3). I tried it with my copy of raylib and the bundled one, with the same result.

flipcoder commented 5 years ago

@carlsmith This happens to me with the same code, but the calls work if you initialize the lib first. Try something like this:

#!/usr/bin/python
import os, sys
os.environ['RAYLIB_BIN_PATH'] = '/usr/lib/'
import raylibpy as raylib

raylib.init_window(800,600, 'Test')
raylib.set_target_fps(60)

while not raylib.window_should_close():
    raylib.begin_drawing()
    raylib.clear_background(raylib.LIGHTGRAY)
    raylib.end_drawing()

raylib.close_window()
carlsmith commented 5 years ago

Ahhh, that makes sense. Thanks, @flipcoder.

An example like that should probably in the README. If your example added a call to draw_text after clear_background, like the official core_basic_window example does, it would be ideal for illustrating how to translate the C examples to Python.

carlsmith commented 5 years ago

Something like this:

import raylibpy as raylib

window_width, window_height = 800, 450
window_title = "Raylib's Basic Window Example in Python"

raylib.init_window(window_width, window_height, window_title)
raylib.set_target_fps(60)

message = "Congrats! You created your first window!"

while not raylib.window_should_close():

    raylib.begin_drawing()
    raylib.clear_background(raylib.RAYWHITE)
    raylib.draw_text(message, 190, 200, 20, raylib.LIGHTGRAY)
    raylib.end_drawing()

raylib.close_window()