StoneLineDevTeam / UMod

GMod replacement project - Sandbox game based on Unreal Engine
BSD 4-Clause "Original" or "Old" License
16 stars 9 forks source link

Lua library function issue... #8

Closed Yuri6037 closed 8 years ago

Yuri6037 commented 8 years ago

All libraries function that needs more than one primitive parameter have a problem and are not able to retrieve correct values from the stack...

Unknown bug can't find anything on internet...

Yuri6037 commented 8 years ago

Yes indead, there is a problem... A big one, Colors are inversed instead of working in correct order RGBA it works at inverse in ABGR ! Lua is a real pain to manipulate... I believe uploading files over the network, and making the net system working, will be much easier than Lua itself ! Lua understands randomly Check instructions at inverse order as you write them in C (I know UNBELIVIABLE !) and sometimes it automaticully corrupts it's own memory ! I haven't even tried to push some user data with raw memory containing pointers, but if the GC starts to corrupt the passed function parameters with only 10 functions, then I would like to know what it will be at a thousand (maybe it will just start to corrupt game memory, in that case I give up as I don't want to have to fix lua to force it to not corrupt the game's RAM)...

If you have any permanent fixes for that please tell, because seriously lua is getting me angry at corrupting memory and refusing to correctly retrieve values from stack !

Yuri6037 commented 8 years ago

Ok I advanced a bit on the issue, it's not random, it's worse : it's always working at inverse : all functions, and absolutely ALL functions are getting parameters at inverse. What I was thinking of a memory corruption because the DrawRect was not working at all (so was getting 0 instead of lua values), is in fact because lua is sending to my surface lib inversed parameters order which causes DrawRect to start drawing the end position before the start position, which is then completely normal it does not work (a rectangle has only one face, not 2 according to how UE4 manages UCanvas rendering !)

Well in other words, if someone finds a better way than inputing parameters at inverse to my functions (currently in order -1, -2, -3, -4... reversed in ..., -4, -3, -2, 1) this should work, but it's realy strange that lua requires you to read parameters in inversed order.

Yuri6037 commented 8 years ago

Ok CheckColor doesn't work at all. After reading one value of a table using C API you indirectly ask lua to corrupt the stack for you, then the result is nil values instead of other values of the table ! When reading a table you must choose to read only one value ! So in conclusion on UMod with the lua53.dll you can't read more than one value of a table passed as function parameter !

Yuri6037 commented 8 years ago

Ok stack corruptions issues are being fixed in the latest commit. Basically just use positive numbers instead of negative ones when working with function arguments.