New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bytecode interpreter (memread / 7) broken? #882
Comments
For reference, the compiled game. |
Of course, if you are using MSVS debugger, then you may pass a path to compiled game in Debugging - Command Arguments project setting. Please note that there is a problem on some systems, supposedly caused by something in Allegro code. It makes mouse and keyboard input lag terribly when breakpoint is hit.
|
@fernewelten , if I use original AGS and compiler I get "z = 8" displayed on screen, as expected. |
For the reference, here's the original compiler's bytecode of the line in question ( load.sp.offs 8 memread ax push ax load.sp.offs 8 memread ax pop bx add bx, ax mov bx, ax mov sp, mar memwrite ax add sp, 4 |
So, if I guess correctly, your compiler allocates new variable on stack before computing its value, while original compiler first computed value then wrote it to stack and advanced stack pointer. From what I see the main difference is this: original compiler was writing value by doing Your compiler does EDIT: But frankly, I doubt this is what causing trouble, because if it did not work then assigning local variables would be broken, is not it?.... |
Yes, that sums it up very well. So the core of the calculation hasn't changed at all, compared to the old compiler. |
@fernewelten load.sp.offs 12 memread ax push ax load.sp.offs 12 memread ax pop bx add bx, ax mov bx, ax memread ax <------------------------ load.sp.offs 4 memwrite ax Notice that extra |
Oh dear. Thanks for the tip.
The spurious |
Yes this is very strange. Unfortunatel I must make a break now. |
Well, I'm going on the hunt now and see where it turns awry. Thanks a ton for all that help, and in the middle of the night, too. Really, I got the surprise of my life when I booked in that bug report in the wee morning hours and found that it already got its first response half an hour later. |
So, I've found the issue: something in the compiler had subtly gone out of sync. Ivan's discovery of that spurious additional command was what pointed me to the problem. I'm still doing some careful additional checks to be on the safe side, but in the meantime I'm assuming the issue to be solved. |
I had this problem too. My registry didn't have the key at all, so I added it as a dword under As far as I understand the problem, Allegro hooks some code into the mouse and keyboard handlers. When the debugger halts the execution at a break point, it halts all the threads, so it halts that hooked code in particular, too. So execution never returns from the hooks, in essence blocking mouse and keyboard completely -- until Windows steps in after some time and forces a time-out. It seems that this |
I'm in AGS 3.5, Commit 4191f0e, where I've added a private branch and added my rewritten compiler to debug it.
For this, I'm using a newly created "Empty Game" where the room 1 has the event "Enters room after fade-in" installed (as
room_AfterFadeIn
).This is the complete room script:
This is the Bytecode that my compiler generates for
int z = f + 11;
in the script given above:Running the program yields
z = 14
, which is correct.Now change that AGS statement to
int z = f + g
Note that the Bytecode has remained exactly the same, except for lines 4 and 5:
Surprisingly, running the program yields
z=5
, which is incorrect.It seems very much that the value pushed at line 3 (namely, 3) is different from the value popped in line 6 (zero, but should still be 3, of course). I very much suspect that
memread ax
in line 5 has somehow clobbered the value pushed onto the stack.This may be related to #869, but I suspect this is a separate issue: I've tried changing lines 3 and 4 into the equivalent lines
so that the only command between the
push ax
and thepop bx
is nowmemread ax
. I still gotz = 5
. So it seems thatload.sp.offs
isn't at fault, butmemread
is.Is there a good way to debug the Engine?
Currently, I'm running programs by opening the solution
AGS.Editor.Full
and hitting F5 to open the AGS Editor; then hitting f5 within the Editor to run the program. The debugger will stop at breakpoints set in the compiler, but not at breakpoints set in the Engine. So I can't step through the bytecode emulation to see what it does.The text was updated successfully, but these errors were encountered: