1. SFML Wrapper Error?

Hello all,

While I went to test one of my SFML wrappers, I noticed I get this error. type check failure code is 1868852841

The line the error originates from is:

without warning 
without type_check 
 
include std/machine.e 
include EuSys2.ew 
include EuGfx2.ew 
 
include sfFlags.e 
 
atom win = sfRenderWindow_create(800,600,32,"My Window",sfClose,0) 
 
if win = -1 then 
	puts(1,"Could not create render window!\n") 
	abort(0) 
end if 
 
constant event = allocate(4 * 6) 
 
while sfRenderWindow_isOpen(win) do 
	 
	while sfRenderWindow_pollEvent(win,event) do 
	 
	  integer eventType = peek4s(event) 
	  integer code = peek4s(event+4) --originates from here 
	  integer alt = peek4s(event+8) 
	  integer control = peek4s(event+13) 
	  integer shift = peek4s(event+16) 
	  integer system = peek4s(event+20) 
	   
		if eventType = sfEvtClosed then 
			sfRenderWindow_close(win) 
		end if 
		 
	end while 
	 
	sfRenderWindow_clear(win,sfBlack) 
	 
	sfRenderWindow_display(win) 
 
end while 
 
sfRenderWindow_destroy(win) 

Any ideas? This worked fine before I updated Euphoria.

new topic     » topic index » view message » categorize

2. Re: SFML Wrapper Error?

Icy_Viking said...

Any ideas? This worked fine before I updated Euphoria.

I think you need to check the value of eventType before attempting to peek deeper into the structure. sfEvent is actually a union, so its contents will be different for the various event types.

-Greg

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

3. Re: SFML Wrapper Error?

ghaberek said...
Icy_Viking said...

Any ideas? This worked fine before I updated Euphoria.

I think you need to check the value of eventType before attempting to peek deeper into the structure. sfEvent is actually a union, so its contents will be different for the various event types.

-Greg

A little more help. I'm confused. It worked fine before I updated to Euphoria version 4.1.0 Beta 2.

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

4. Re: SFML Wrapper Error?

Icy_Viking said...

A little more help. I'm confused. It worked fine before I updated to Euphoria version 4.1.0 Beta 2.

I just had some time to sit down and test your code. I get the same error on 4.0 or 4.1 32-bit.

You're storing the values as integer, but sometimes you might not get back a value that fits into an integer type, which is only 31-bits on 32-bit platforms. I ran your code many times and once or twice I got an error that type check error. It seems this only occurs when the library loads into an area of memory that already exceeds the size of an integer.

One thing to keep in mind about Windows, is that it basically has a mind of its own when it comes to unloading DLLs from memory. It will hang onto them for some indeterminate period of time and then release them. So, if your application runs the first time and it works, it will keep working until some time goes by without the application having loaded the DLL. Then, you have a random chance of Windows loading the DLL into a larger-than-integer area of memory.

Regardless of the cause, the solution is simple: when accessing memory directly with peek/poke routines, always store your values as atom types.

-Greg

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

5. Re: SFML Wrapper Error?

ghaberek said...
Icy_Viking said...

A little more help. I'm confused. It worked fine before I updated to Euphoria version 4.1.0 Beta 2.

I just had some time to sit down and test your code. I get the same error on 4.0 or 4.1 32-bit.

You're storing the values as integer, but sometimes you might not get back a value that fits into an integer type, which is only 31-bits on 32-bit platforms. I ran your code many times and once or twice I got an error that type check error. It seems this only occurs when the library loads into an area of memory that already exceeds the size of an integer.

One thing to keep in mind about Windows, is that it basically has a mind of its own when it comes to unloading DLLs from memory. It will hang onto them for some indeterminate period of time and then release them. So, if your application runs the first time and it works, it will keep working until some time goes by without the application having loaded the DLL. Then, you have a random chance of Windows loading the DLL into a larger-than-integer area of memory.

Regardless of the cause, the solution is simple: when accessing memory directly with peek/poke routines, always store your values as atom types.

-Greg

I changed them from integer to atom types and it worked! Thanks Greg. I'll keep this in mind when wrapping the next version of SFML. Also, for whenever SFML 3 will be released.

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

6. Re: SFML Wrapper Error?

Icy_Viking said...
	  integer alt = peek4s(event+8) 
	  integer control = peek4s(event+13) 
	  integer shift = peek4s(event+16) 

I have to say that I would be quite surprised if that should not be

	  integer alt = peek4s(event+8) 
	  integer control = peek4s(event+12) 
	  integer shift = peek4s(event+16) 
new topic     » goto parent     » topic index » view message » categorize

7. Re: SFML Wrapper Error?

petelomax said...
Icy_Viking said...
	  integer alt = peek4s(event+8) 
	  integer control = peek4s(event+13) 
	  integer shift = peek4s(event+16) 

I have to say that I would be quite surprised if that should not be

	  integer alt = peek4s(event+8) 
	  integer control = peek4s(event+12) 
	  integer shift = peek4s(event+16) 

I did test with changing the +13 part to +12 and I still got the routine bad number error after I changed them to integer values just for testing purposes. I had to change them back to atom types for it to work again.

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

8. Re: SFML Wrapper Error?

Icy_Viking said...
petelomax said...
Icy_Viking said...
 
  integer alt = peek4s(event+8) 
  integer control = peek4s(event+13) 
  integer shift = peek4s(event+16) 

I have to say that I would be quite surprised if that should not be

 
  integer alt = peek4s(event+8) 
  integer control = peek4s(event+12) 
  integer shift = peek4s(event+16) 

I did test with changing the +13 part to +12 and I still got the routine bad number error after I changed them to integer values just for testing purposes. I had to change them back to atom types for it to work again.

No, Pete's right. sfBool is typedef'd as an int so the offsets should all be four-byte aligned.

https://github.com/SFML/CSFML/blob/master/include/SFML/Config.h#L150

This is why I always recommend planning out structs with constant instead of using magic numbers.

https://github.com/SFML/CSFML/blob/master/include/SFML/Window/Event.h#L72

//////////////////////////////////////////////////////////// 
/// \brief Keyboard event parameters 
///  
//////////////////////////////////////////////////////////// 
typedef struct 
{ 
    sfEventType type; 
    sfKeyCode   code; 
    sfBool      alt; 
    sfBool      control; 
    sfBool      shift; 
    sfBool      system; 
} sfKeyEvent; 

constant 
    sfKeyEvent__type    =  0, -- sfEventType (int) 
    sfKeyEvent__code    =  4, -- sfKeyCode   (int) 
    sfKeyEvent__alt     =  8, -- sfBool      (int) 
    sfKeyEvent__control = 12, -- sfBool      (int) 
    sfKeyEvent__shift   = 16, -- sfBool      (int) 
    sfKeyEvent__system  = 20, -- sfBool      (int) 
    SIZEOF_SFKEYEVENT   = 24, 
$ 
 
atom alt     = peek4s( event + sfKeyEvent__alt ) 
atom control = peek4s( event + sfKeyEvent__control ) 
atom shift   = peek4s( event + sfKeyEvent__shift ) 

-Greg

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

9. Re: SFML Wrapper Error?

ghaberek said...
Icy_Viking said...
petelomax said...
Icy_Viking said...
 
  integer alt = peek4s(event+8) 
  integer control = peek4s(event+13) 
  integer shift = peek4s(event+16) 

I have to say that I would be quite surprised if that should not be

 
  integer alt = peek4s(event+8) 
  integer control = peek4s(event+12) 
  integer shift = peek4s(event+16) 

I did test with changing the +13 part to +12 and I still got the routine bad number error after I changed them to integer values just for testing purposes. I had to change them back to atom types for it to work again.

No, Pete's right. sfBool is typedef'd as an int so the offsets should all be four-byte aligned.

https://github.com/SFML/CSFML/blob/master/include/SFML/Config.h#L150

This is why I always recommend planning out structs with constant instead of using magic numbers.

https://github.com/SFML/CSFML/blob/master/include/SFML/Window/Event.h#L72

//////////////////////////////////////////////////////////// 
/// \brief Keyboard event parameters 
///  
//////////////////////////////////////////////////////////// 
typedef struct 
{ 
    sfEventType type; 
    sfKeyCode   code; 
    sfBool      alt; 
    sfBool      control; 
    sfBool      shift; 
    sfBool      system; 
} sfKeyEvent; 

constant 
    sfKeyEvent__type    =  0, -- sfEventType (int) 
    sfKeyEvent__code    =  4, -- sfKeyCode   (int) 
    sfKeyEvent__alt     =  8, -- sfBool      (int) 
    sfKeyEvent__control = 12, -- sfBool      (int) 
    sfKeyEvent__shift   = 16, -- sfBool      (int) 
    sfKeyEvent__system  = 20, -- sfBool      (int) 
    SIZEOF_SFKEYEVENT   = 24, 
$ 
 
atom alt     = peek4s( event + sfKeyEvent__alt ) 
atom control = peek4s( event + sfKeyEvent__control ) 
atom shift   = peek4s( event + sfKeyEvent__shift ) 

-Greg

Thanks for the tips. I'll keep this in mind.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu