1. Type check failure (New problem now)

Hello,

I was writing some examples for my raylib wrapper and I got this error. type_check failure, str is 44541448. The help files in the raylib says it uses the default text when using the DrawText command. I'm not sure what is causing the error.

--Wrapper code 
public constant xDrawText = define_c_proc(ray,"+DrawText",{C_POINTER,C_INT,C_INT,C_INT,C_UCHAR,C_UCHAR,C_UCHAR,C_UCHAR}) 
 
public procedure DrawText(sequence text,atom x,atom y,atom size,atom r,atom g,atom b,atom a) 
 
 --sequence str = allocate_string(text,1) --I figured out the error, I had this as a sequence, when I should have had it as a atom. 
 atom str = allocate_string(text,1) --correct code 
  
 c_proc(xDrawText,{str,x,y,size,r,g,b,a}) 
	 
end procedure 
--Example Code 
without warning 
 
include std/machine.e 
include flags.e 
include Euraylib.ew 
 
atom width = 800 
atom height = 450 
 
InitWindow(width,height,"Input") 
 
SetTargetFPS(60) 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
	 
	ClearBackground(0) 
	 
   DrawText("Move ball with arrow keys",10,10,20,255,255,255,255) 
	 
	EndDrawing() 
	 
end while 
 
CloseWindow() 

Ok now I can't figure out why the color won't work. I have them assigned as r,g,b,a values, but only red appears to be working.

--Wrapper code 
public constant xClearBackground = define_c_proc(ray,"+ClearBackground",{C_UCHAR,C_UCHAR,C_UCHAR,C_UCHAR}) 
 
public procedure ClearBackground(atom r,atom g,atom b,atom a) 
 
 c_proc(xClearBackground,{r,g,b,a}) 
	 
end procedure 
--Example 
without warning 
 
include std/machine.e 
include flags.e 
include Euraylib.ew 
 
atom width = 800 
atom height = 450 
 
InitWindow(width,height,"Input") 
 
SetTargetFPS(60) 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
	 
        --r,g,b,a for 255,0,0,0 
	ClearBackground(100,0,0,0) --only the r variable seems to be being ready, the g,b,a don't seem to effect it at all. 
	--changing it to 255,255,255,255 makes it blank, when it should appear white 
	EndDrawing() 
	 
end while 
new topic     » topic index » view message » categorize

2. Re: Type check failure (New problem now)

Icy_Viking said...

Ok now I can't figure out why the color won't work. I have them assigned as r,g,b,a values, but only red appears to be working.

--Wrapper code 
public constant xClearBackground = define_c_proc(ray,"+ClearBackground",{C_UCHAR,C_UCHAR,C_UCHAR,C_UCHAR}) 

I'm pretty sure that this method still passes the arguments to the function as 4-byte values. It's just going to ensure they're the lower 8 bits and strip the upper 24 bits.

Try packing the values into a single C_UINT value instead. Use bytes_to_int({ r, g, b, a }) and pass that as a single argument to ClearBackground.

typedef struct Color { 
    unsigned char r; 
    unsigned char g; 
    unsigned char b; 
    unsigned char a; 
} Color; 
 
RLAPI void ClearBackground(Color color); // Set background color (framebuffer clear color) 

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: Type check failure (New problem now)

ghaberek said...
Icy_Viking said...

Ok now I can't figure out why the color won't work. I have them assigned as r,g,b,a values, but only red appears to be working.

--Wrapper code 
public constant xClearBackground = define_c_proc(ray,"+ClearBackground",{C_UCHAR,C_UCHAR,C_UCHAR,C_UCHAR}) 

I'm pretty sure that this method still passes the arguments to the function as 4-byte values. It's just going to ensure they're the lower 8 bits and strip the upper 24 bits.

Try packing the values into a single C_UINT value instead. Use bytes_to_int({ r, g, b, a }) and pass that as a single argument to ClearBackground.

typedef struct Color { 
    unsigned char r; 
    unsigned char g; 
    unsigned char b; 
    unsigned char a; 
} Color; 
 
RLAPI void ClearBackground(Color color); // Set background color (framebuffer clear color) 

-Greg

--Wrapper Code 
public constant xDrawText = define_c_proc(ray,"+DrawText",{C_POINTER,C_INT,C_INT,C_INT,C_UINT}) 
 
public procedure DrawText(sequence text,atom x,atom y,atom size,atom col) 
 
 atom str = allocate_string(text,1) 
  
 c_proc(xDrawText,{str,x,y,size,col}) 
	 
end procedure 
--Example 
without warning 
 
include std/machine.e 
include flags.e 
include Euraylib.ew 
 
atom width = 800 
atom height = 450 
 
InitWindow(width,height,"Input") 
 
SetTargetFPS(60) 
 
atom r = bytes_to_int({255,255,255,255}) 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
	 
	ClearBackground(r) 
	 
	EndDrawing() 
	 
end while 
 
CloseWindow() 

I tried what you advised and it didn't work. Or I'm going about it wrong?

EDIT: My Apologies. I had the wrong function shown, I fixed it for ClearBackground and it works! Thanks Greg. Now I just need to do this for the other color related functions.

--Wrapper 
public constant xClearBackground = define_c_proc(ray,"+ClearBackground",{C_UINT}) 
 
public procedure ClearBackground(atom col) 
 
 c_proc(xClearBackground,{col}) 
	 
end procedure 
--Example 
without warning 
 
include std/machine.e 
include std/convert.e 
include flags.e 
include Euraylib.ew 
 
atom width = 800 
atom height = 450 
 
InitWindow(width,height,"Input") 
 
SetTargetFPS(60) 
 
atom r = bytes_to_int({0,255,0,255}) 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
	 
	ClearBackground(r) 
	 
	EndDrawing() 
	 
end while 
 
CloseWindow() 
new topic     » goto parent     » topic index » view message » categorize

4. Re: Type check failure (New problem now)

One thing I'd add, is that maybe it's a bit easier on the end user to put the bytes_to_int call inside your wrapper.

public constant xClearBackground = define_c_proc(ray,"+ClearBackground",{C_UINT}) 
 
public procedure ClearBackground(object col) 
 
  if sequence( col ) then 
    col = bytes_to_int( col ) 
  end if 
 
  c_proc(xClearBackground,{col}) 
	 
end procedure 
--Example 
without warning 
 
include flags.e 
include Euraylib.ew 
 
atom width = 800 
atom height = 450 
 
InitWindow(width,height,"Input") 
 
SetTargetFPS(60) 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
	 
	ClearBackground({0,255,0,255}) 
	 
	EndDrawing() 
	 
end while 
 
CloseWindow() 

-Greg

new topic     » goto parent     » topic index » view message » categorize

5. Re: Type check failure (New problem now)

ghaberek said...

One thing I'd add, is that maybe it's a bit easier on the end user to put the bytes_to_int call inside your wrapper.

public constant xClearBackground = define_c_proc(ray,"+ClearBackground",{C_UINT}) 
 
public procedure ClearBackground(object col) 
 
  if sequence( col ) then 
    col = bytes_to_int( col ) 
  end if 
 
  c_proc(xClearBackground,{col}) 
	 
end procedure 
--Example 
without warning 
 
include flags.e 
include Euraylib.ew 
 
atom width = 800 
atom height = 450 
 
InitWindow(width,height,"Input") 
 
SetTargetFPS(60) 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
	 
	ClearBackground({0,255,0,255}) 
	 
	EndDrawing() 
	 
end while 
 
CloseWindow() 

-Greg

Thanks for the idea, Greg.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu