Closed SirNate0 closed 4 months ago
The probability that this is caused by something in raylib-python-cffi and not something in Raylib (or Spyder, or IPython, or Matplotlib) is pretty small. And even if it is, I probably don't know enough about those projects to diagnose it.
However, somebody from those projects might be reading this, so I suggest you provide detailed, step by step instructions how to reproduce the issue, including screen shots.
Here's all that I can provide. I'm really not sure of what's going on myself - even what I said above seems incorrect - I'm having issues (a little inconsistently) regardless of that setting now, but only on the second run of the code. The first time it seems to work fine.
from pyray import *
init_window(640,480, "Hello")
while not window_should_close():
begin_drawing()
clear_background(BLACK)
draw_text("Hello world", 190, 200, 20, VIOLET)
if gui_button(Rectangle(10,10,100,32),"TEST"):
print("TEST pressed")
end_drawing()
close_window()
The first run (with Run or F5):
The second run
If it helps in reproducing it, for the IPython console, it's running
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
with these packages in the venv
asttokens==2.4.1
cffi==1.16.0
cloudpickle==3.0.0
comm==0.2.1
debugpy==1.8.0
decorator==5.1.1
exceptiongroup==1.2.0
executing==2.0.1
inflection==0.5.1
ipykernel==6.29.0
ipython==8.20.0
jedi==0.19.1
jupyter_client==8.6.0
jupyter_core==5.7.1
matplotlib-inline==0.1.6
nest-asyncio==1.6.0
packaging==23.2
parso==0.8.3
pexpect==4.9.0
platformdirs==4.1.0
prompt-toolkit==3.0.43
psutil==5.9.8
ptyprocess==0.7.0
pure-eval==0.2.2
pycparser==2.21
Pygments==2.17.2
python-dateutil==2.8.2
pyzmq==25.1.2
raylib==5.0.0.1
six==1.16.0
spyder-kernels==2.4.4
stack-data==0.6.3
tornado==6.4
traitlets==5.14.1
wcwidth==0.2.13
wurlitzer==3.0.3
Actually, this may have nothing to do with Spyder and such. If I just run this code from the terminal, I observe the same behavior - no text on buttons on the second window:
from pyray import *
init_window(640,480, "Hello")
while not window_should_close():
begin_drawing()
clear_background(BLACK)
draw_text("Hello world", 190, 200, 20, VIOLET)
if gui_button(Rectangle(10,10,100,32),"TEST"):
print("TEST pressed")
end_drawing()
close_window()
init_window(640,480, "Hello")
while not window_should_close():
begin_drawing()
clear_background(BLACK)
draw_text("Hello world", 190, 200, 20, VIOLET)
if gui_button(Rectangle(10,10,100,32),"TEST"):
print("TEST pressed")
end_drawing()
close_window()
Thanks. I've translated your program to C:
#include <stdio.h>
#include "raylib.h"
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
int main(void){
InitWindow(640,480, "Hello");
while(!WindowShouldClose()){
BeginDrawing();
ClearBackground(BLACK);
DrawText("Hello world", 190, 200, 20, VIOLET);
if(GuiButton((Rectangle){10,10,100,32},"TEST")){
printf("TEST pressed");
}
EndDrawing();
}
CloseWindow();
InitWindow(640,480, "Hello");
while(!WindowShouldClose()){
BeginDrawing();
ClearBackground(BLACK);
DrawText("Hello world", 190, 200, 20, VIOLET);
if(GuiButton((Rectangle){10,10,100,32},"TEST")){
printf("TEST pressed");
}
EndDrawing();
}
CloseWindow();
return 0;
}
The bug is exactly the same, therefore it's a bug in Raylib rather than raylib-python-cffi.
It's likely that Raylib doesn't clean up after itself fully on CloseWindow.
I suggest you report the issue to Raylib, however I expect they will say that opening two windows in the same progarm is simply not supported.
A very odd issue, but when running ~~from Spyder's IPython console with
IPython console > Graphics > Support for graphics (Matplotlib) > Activate support
activated (with default Inline backend, etc.), I end up with no text rendering on the buttons. If I deactivate it, the text works fine, or if I run directly from the terminal. And in all cases, draw_text works fine.~~ This may have been coincidental (closing the IPython console with the setting change, some segmentation faults causing a reset, etc.).The true cause may have just be from the IPython kernel persisting between runs of the script. if I just duplicated a script (two
init_window()...close_window()
pairs -- minimal example below) I get the same result - no text on the buttons on the second run.