PDA

View Full Version : Report a hidden bug



xLeaves
20-01-2020, 10:01
There may be logic errors in parsing when writing code for loops or array operations.

Although the code is correct, ThinBasic reports errors.

The magic thing is that as long as you add a piece of code that doesn't work, it will run without problems.

You can compare the code in these two pictures.

10109

10110

The error is on line 259, so I added some debugging in the front (output the content to dbgview), and then no more error.

In fact, I have encountered such inexplicable problems in various programming I have done before. Often when I troubleshoot the problem, I add the code output to dbgview and the problem is solved.

I think this should be a bug on the grammar or lexer, but this problem is difficult to reproduce and it is difficult to find the smallest use case.

So I do n’t know how to report this problem, I hope ErosOlmi will do some troubleshooting.

xLeaves
20-01-2020, 10:09
10111

This is another similar problem encountered some time ago.

The loop can't jump out normally. Adding some useless code in front of the loop can solve it, but the code is always modified, so the problem that can't jump out always appears, so I can only judge inside the loop to solve this problem.



Say something off topic

Earlier Petr Schreiber told me that ThinBasic only performs the most basic syntax check on the code at runtime to improve the efficiency of the operation.

Has ErosOlmi considered developing a bytecode instruction system for ThinBasic?

This results in more complete syntax checking and better performance.

Of course, this is a time-consuming work. It is not suitable to add in the current version. It may be carried out when porting to FreeBasic.

DirectuX
21-01-2020, 14:58
Hi xLeaves,

in the first post I can't read, it's too small.

In the second post, what is the problem with loop exit ? Please post the code that fails.

Petr Schreiber
23-01-2020, 20:33
Hi xLeaves,

the best would be to isolate the issue to the replicable example.

On the first RunTimeError, I can see thinBasic complains that you pass index of array as 0, but the array has dimensions 1 to 60.

So, in this case, I might be zero, or ILevel might be zero. Please try to print these two to console or break the expression to smaller ones.


Petr

ErosOlmi
25-01-2020, 12:37
Ciao xLeaves,

If I saw well from images

the first is a array "subscription out of range" that is script try to read element index <= 0 or > max number of array elements. In this case zero
But it seems that changing some code, problem seems solved.
the second seems that EXIT DO doesn't work as expected.



I would like to analyze and fix such issues but I need to have a piece of code that I can run.
If you are able to isolate in a script that you can attach here ... it would be of great help.

In the mean time I will try to see EXIT DO issue that is more easy to verify for me.
EXIT DO internally scan the code in order to find next LOOP having the same indent level of the current loop.
It can be "bad" influenced by how the code is written, maybe I missed some programming behave.

xLeaves
25-01-2020, 21:16
Dear ErosOlmi, and everyone who responded:

I'm sorry that I haven't responded to this question. After posting, I didn't check whether the image is clear, so that you can't see the error code.
I have developed some tools using ThinBasic. At present, the above error occurs in a project of about 3000 lines. The reason why the code to reproduce the problem is not provided is simply because when I try to simplify the code , The error disappeared, I will attach the complete project code and point out the specific error location.

10118

This source code runs on ThinBasic 1.11.2.0 and was developed using LzRPA. Lzbot_test_boot.tbasic and lzbot_test_main.tbasic are the generated source code. Just run lzbot_test_boot.tbasic.

Its role is to generate a bunch of XML documents used in the game based on an Excel spreadsheet. The spreadsheet file name is:设计表.xlsx (Can be opened with Office 2007 and above)

After running, he will output documents such as item.xml, suit.xml, monster.xml, drop.xml, etc.



Next, I will mark the error code:

The first paragraph, adding irrelevant code does not report an error

In lines 2888 and 2889 of lzbot_test_main.tbasic, the problem is that when I comment out the 2888 lines of code, an array overflow error is raised (in fact, I tried to output the length and data of the array, and it didn't Overflow), and when this line of code runs, the array will not overflow, and the function of this line of code is just to output a message to my IDE, I do not know why it will affect the results of the next line.


For i = sDropMid To sDropHigh
Dim iLevel As Long = i - sDropMid + 1
Dim iPrevDrop As Long = 0
If iLevel > 1 Then
iPrevDrop = DropRate(iLevel - 1)
End If
TracePrint "动态爆率:" & iLevel & ",阶数:" & i & ",上一阶分母:" & iPrevDrop ' Error Point
DropRate(iLevel) = (((DropWeight(i) * 8) + 2) * HighDrop(iLevel)) + iPrevDrop ' Error Point
Next

The second problem does not jump out of the loop

It happened on line 1964, you can see that the While part of this line of code is commented out, and on line 1970, I added another judgment to avoid the situation where the loop cannot break out. I guess this problem is caused by the data type, it It's been a long time and I haven't continued to study the cause and try to fix it, maybe I can take a look recently.


ItemLine = 2
Do 'While (Sheet_Item.Cells(ItemLine, 3).Value <> "") ‘ Error Point

' 读取记录生成装备数据
ItemLevel = Sheet_Item.Cells(ItemLine, 1).Value
sLevel = Sheet_Item.Cells(ItemLine, 2).Value
sKeyName = Sheet_Item.Cells(ItemLine, 3).Value
If sKeyName = "" Then ‘ Error Point
Exit Do
End If
TracePrint("正在处理 " & sKeyName)

xLeaves
25-01-2020, 21:44
Sorry to mention these two very strange questions. I understand very well the idea that a programmer wants the simplest use case to troubleshoot. When my tool encounters a bug, I usually want the simplest steps to reproduce it. , But these problems did come after I wrote a certain number of lines of code.

In addition, a new problem is reported here:

When a Declare statement defines an external DLL function, if an extra layer of encapsulation is used on the basis of this function, and it happens to have the same parameter name, an error will be reported, for example:


Declare Sub Sleep Lib "kernel32.dll" Alias "Sleep" (ByVal ms As Long)

Function MySleep(ByVal ms As Long)
Sleep(ms)
End Function

Function Main() As Long
MsgBox("Hello World")
MySleep(1000)
MsgBox("Hello World2")
End Function

ErosOlmi
26-01-2020, 19:15
Sorry to mention these two very strange questions. I understand very well the idea that a programmer wants the simplest use case to troubleshoot. When my tool encounters a bug, I usually want the simplest steps to reproduce it. , But these problems did come after I wrote a certain number of lines of code.

In addition, a new problem is reported here:

When a Declare statement defines an external DLL function, if an extra layer of encapsulation is used on the basis of this function, and it happens to have the same parameter name, an error will be reported, for example:


Declare Sub Sleep Lib "kernel32.dll" Alias "Sleep" (ByVal ms As Long)

Function MySleep(ByVal ms As Long)
Sleep(ms)
End Function

Function Main() As Long
MsgBox("Hello World")
MySleep(1000)
MsgBox("Hello World2")
End Function


Here the problem is that you cannot declare an external function having the same name of thinBasic keyword.
"Sleep" is a thinBasic keyword so you get an error.

You can declare it with a different name:

Declare Sub MyVersionOfSleep Lib "kernel32.dll" Alias "Sleep" (ByVal ms As Long)



Regarding the intermittent error reported above ... I'm testing.
At first sight the only thing I've seen is that is strange is that you DIM variable inside loops and I didn't consider that fact.

Usually DIM ... should be placed outside loops.
When thinBasic see DIM <VariableName> As <VariableType> it checks if <VariableName> is already defined in the current stack level.
If yes, it check if <VariableType> is the same of the already defined variable.
If also this is true, DIM is just ignored.
But having so much DIM <VariableName> As <VariableType> = <expression> can be a problem.
Anyway ... going on in checking

xLeaves
27-01-2020, 23:41
Here the problem is that you cannot declare an external function having the same name of thinBasic keyword.
"Sleep" is a thinBasic keyword so you get an error.

You can declare it with a different name:

Declare Sub MyVersionOfSleep Lib "kernel32.dll" Alias "Sleep" (ByVal ms As Long)



Regarding the intermittent error reported above ... I'm testing.
At first sight the only thing I've seen is that is strange is that you DIM variable inside loops and I didn't consider that fact.

Usually DIM ... should be placed outside loops.
When thinBasic see DIM <VariableName> As <VariableType> it checks if <VariableName> is already defined in the current stack level.
If yes, it check if <VariableType> is the same of the already defined variable.
If also this is true, DIM is just ignored.
But having so much DIM <VariableName> As <VariableType> = <expression> can be a problem.
Anyway ... going on in checking

Thank you ErosOlmi. The last question is my negligence. I'm very sorry to ask you to verify such a question.