Lua x DirectX

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua x DirectX

Roberto Ierusalimschy
It seems that too many people are having problems with this DirectX issue.
How can we solve that??

- Some people suggested adding some warning in the manual. Would this
really help? I mean, if you find an unexpected bug in a program, where
will you search for help? In the manual? In what section?

- Another option would be to simply turn off the offending macro
(lua_number2int) in Windows. This will slow down Lua a bit... Of
course, anyone is free to use it, but the default would avoid the
problem. (Doesn't Windows offer lrint? Could we use it instead?)

- Other option would be to add a check somewhere in the code, so
that this situation is detected early and gives a proper error message.
(Unfortunately, the test cannot be when creating a Lua state, because
there is no way to return an error message. Maybe when loading a chunk?)

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Lua x DirectX

Adam D. Moss
Roberto Ierusalimschy wrote:
It seems that too many people are having problems with this DirectX issue.
How can we solve that??

doc + runtime check sounds ideal to me.  Sure, the offending
macro could be turned off, but someone running default-D3D
combined with double-Lua with or without this macro is a fair
indication that they're simply unaware that their precision is
being decimated.  Thus a warning should be issued that refers
developers to their three options:
* Don't let D3D mess with their double maths (surely the sane
choice for anyone who isn't very, very familiar with the
practical precision requirements of ALL third-party code and
libraries they're using, probably-negligible D3D performance
hit be damned).
* Recompile Lua with floats instead of doubles, at least
making it explicit that they're getting single precision
* Compile-out the Lua warning and disable the spicey
macro, where the developer is confident that they can
live with the precision hit and moving to explicit floats
isn't an option (i.e. LuaJIT users).

--adam


Reply | Threaded
Open this post in threaded view
|

RE: Lua x DirectX

Couwenberg, Wim
In reply to this post by Roberto Ierusalimschy
> It seems that too many people are having problems with this 
> DirectX issue.
> How can we solve that??

It is not only a DirectX issue, that's just one library that is a known
offender.  And, unfortunately, the number2int macro isn't the only
issue...  We've had this fp control word trouble even in a Lua 4
project.  Our app would crash at strange and unpredictable places.  It
took us a *long* time to pinpoint the problem.  In our case, a sound
driver changed the fp control word.  If I remember correctly, the crash
was then caused by a fp underflow (or overflow) exception that was
thrown at us (instead of being silently ignored.)  To make things worse,
this exception is not thrown immediately, but it remains pending until
some further interaction with the fpu (I've forgotten the details, but
it was pretty hairy stuff.)

We fixed this by explicitly restoring the fp control word following a
PlaySound call.  Maybe this could be integrated by providing a
lua_set_fpcw macro (like the lua_lock/lua_unlock) that is executed after
each C call?

--
Wim

--8<--discard--8<--discard--8<--discard--8<--

This message and attachment(s) are intended solely for the use of the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.  
If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited.  
If you have received this communication in error, please notify the sender immediately by telephone and with a "reply" message.  
Thank you for your cooperation.




Reply | Threaded
Open this post in threaded view
|

Re: Lua x DirectX

Adrian Sietsma
In reply to this post by Roberto Ierusalimschy
Roberto Ierusalimschy wrote:
It seems that too many people are having problems with this DirectX issue.
How can we solve that??

- Some people suggested adding some warning in the manual. Would this
really help? I mean, if you find an unexpected bug in a program, where
will you search for help? In the manual? In what section?

- Another option would be to simply turn off the offending macro
(lua_number2int) in Windows. This will slow down Lua a bit... Of
course, anyone is free to use it, but the default would avoid the
problem. (Doesn't Windows offer lrint? Could we use it instead?)

- Other option would be to add a check somewhere in the code, so
that this situation is detected early and gives a proper error message.
(Unfortunately, the test cannot be when creating a Lua state, because
there is no way to return an error message. Maybe when loading a chunk?)

As a minimum, can we add a test in the debug library, maybe on load ?
Also maybe set/get FPW functions there ?

Adrian



Reply | Threaded
Open this post in threaded view
|

Re: Lua x DirectX

D Burgess-4
In reply to this post by Roberto Ierusalimschy
My vote, as alluded to another thread, is have a set of external
test programs, that expose such errors, e.g. a regression
test suite.

DB


Reply | Threaded
Open this post in threaded view
|

Re: Lua x DirectX

Roberto Ierusalimschy
On Sat, Mar 18, 2006 at 09:58:42AM +1100, D Burgess wrote:
> My vote, as alluded to another thread, is have a set of external
> test programs, that expose such errors, e.g. a regression
> test suite.
> 

A standard regression test in the distribution would certanly be
helpful, but it would not detect that problem, since it would not invoke
DirectX...

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Lua x DirectX

D Burgess-4
I was hoping that someone could donate some C/Lua code that
would detect the problem. Not posiible?


Reply | Threaded
Open this post in threaded view
|

Re: Lua x DirectX

Adam D. Moss
D Burgess wrote:
I was hoping that someone could donate some C/Lua code that
would detect the problem. Not posiible?

A few people posted suggestions -- I think Mike Pall
posted some.  Untested though.

--adam



XIX
Reply | Threaded
Open this post in threaded view
|

Re: Lua x DirectX

XIX
In reply to this post by Roberto Ierusalimschy

There isn't really anything to do to fix it, since its not your problem. You can't make sure you always catch it going wrong either. So I don't think that is really worth thinking about.

Changing the macro doesn't really fix the problem either, it just makes it less obvious, which is worse.

Ultimately anyone who encounters this bug is now better of knowing that they had a problem. (: Including myself :)

Just make sure it is documented somewhere as part of a list of common mistakes or misunderstandings with lua.

In bold, large, letters, on the cover of "the book", is my personal location preference for such a list.

--

Kriss

http://XIXs.com -><- http://www.WetGenes.com