Feature request: Debugging capabilities for scripts

User avatar
Mikko Merikivi
Posts: 18
Joined: Fri Sep 13, 2013 9:04 pm

Feature request: Debugging capabilities for scripts

Postby Mikko Merikivi » Sun Oct 06, 2013 10:20 am

I don't understand why debugging capabilities for scripting based errors are so overlooked by the Stratagus staff. At least for new or experimenting projects (or in my case, upgrading from an old Stratagus) when a crash happens chances are it's because of their own mistake in scripting. Stratagus then cannot even tell which script file it was reading when it happened. Also, perhaps I'm not just a good enough user but gdb rarely is of any use either because it cannot tell which LUA files were opened recently.

I'll give an example. A place I have had a lot of crashes is in the function DrawTexture and Stratagus will say this when a crash happens:
Assertion failed at /home/mikko/Games/stratagus_2.2.7.patched/src/video/sprite.cpp:95: DrawTexture: gx_end <= g->GraphicWidth

How is that supposed to help? Well, excuse me but I have 141 units (obviously, not all of them have their own graphic files but each define the width and height of the graphic files individually) and the function covers probably even more graphics than those.

Here's a quick fix I made for this specific problem (with horrible coding as usual) but a more general tracker of which LUA files have been accessed recently would also be really nice.
*** ../src/video/sprite.cpp 2013-10-06 02:40:00.159718645 +0300
--- ../../stratagus_2.2.7.veryorig/src/video/sprite.cpp 2013-10-03 19:56:26.445550587 +0300
***************
*** 90,100 ****
Assert(0 <= gy_beg);
Assert(gx_beg <= gx_end); // draws nothing if equal
Assert(gy_beg <= gy_end); // draws nothing if equal
! if(gx_end > g->GraphicWidth || gy_end > g->GraphicHeight) {
! printf("DrawTexture failed because %s has incorrect width or height.\n", g->File.c_str());
! Assert(gx_end <= g->GraphicWidth);
! Assert(gy_end <= g->GraphicHeight);
! }

for (int tex_gy_beg = gy_beg / GLMaxTextureSize * GLMaxTextureSize;;
tex_gy_beg += GLMaxTextureSize) {
--- 90,97 ----
Assert(0 <= gy_beg);
Assert(gx_beg <= gx_end); // draws nothing if equal
Assert(gy_beg <= gy_end); // draws nothing if equal
! Assert(gx_end <= g->GraphicWidth);
! Assert(gy_end <= g->GraphicHeight);

for (int tex_gy_beg = gy_beg / GLMaxTextureSize * GLMaxTextureSize;;
tex_gy_beg += GLMaxTextureSize) {
User avatar
jarod42
Posts: 101
Joined: Fri Jan 20, 2012 7:43 pm

Re: Feature request: Debugging capabilities for scripts

Postby jarod42 » Sun Oct 06, 2013 8:09 pm

`Assert` should be used to track internal error.
scripting/data errors should be reported to the user.

I don't know a good way to debug lua code from stratagus, sorry.
(I saw some lua debuggers, but they seems to only debug lua code launch 'alone'
(so not from stratagus :/)).

Stratagus coders are not very active now... :-(
lua scripters/moders seems to be more now... :-)

Internal code need a lot of improvement to help lua coders...

For your patch, I would say that the check should be done when loading the graphic, and not when displaying it.
User avatar
Mikko Merikivi
Posts: 18
Joined: Fri Sep 13, 2013 9:04 pm

Re: Feature request: Debugging capabilities for scripts

Postby Mikko Merikivi » Sun Oct 06, 2013 11:07 pm

For your patch, I would say that the check should be done when loading the graphic, and not when displaying it.
Actually my problem was that I had defined too many frames for my graphic file in the animations. How does that change your opinion on where to put the check? Another thing where just a check at loading wouldn't catch a problem is if there's an erroneous offset.

But I agree that if it's in the drawing of graphics it will be called far too often and it would slow down the game.
User avatar
Big Daddy
Posts: 118
Joined: Sun Jan 08, 2012 11:23 pm

Re: Feature request: Debugging capabilities for scripts

Postby Big Daddy » Mon Oct 07, 2013 8:54 pm

I like this guy.

Who is online

Users browsing this forum: No registered users and 1 guest