BASS_FXSetParameters , fVolume : Overflow error

Started by Couin,

Couin

Hi friends :)

I got once, an Overflow error ( #6 ) at line 2, but I can not reproduce it :(

How can I prevent to this error coming back ? Here is my code :)

Thanks :)
Couin

' update volume
Public Sub UpdateVol(ByVal fxvol As Long, ByVal v As Integer)

1         On Error GoTo Error_Routine

2         pvol.fVolume = 0.01 * v
3         Call BASS_FXSetParameters(fxvol, pvol)

Exit_Routine:
4         Exit Sub
Error_Routine:
5         If err.Number <> 0 Then
6             Debug.Assert False
7             ErrorLog "modClick.UpdateVol"
8             Resume Exit_Routine
9         End If
End Sub

jpf

My guess is that somewhere else in your code you're disrupting the VB6 runtime.

There are bugs in the runtime that lead to vulnerabilities. One well known way of telling if an array is unititialized (something like "If (Not array) = -1 Then", that was the fashion 25 years ago) was later found to corrupt the runtime. May it be that you code uses this or other undocumented and potentialy risky code to achive some things?

If that's the case VB6 error handling routines will also fail sometimes and also other unrelated parts of your code will be affected. Else you may probably live with this by adding error handling routines here and there.

If you can't replicate the error it will be difficult to sort out.

The expression "0.01 * v" where v is an integer and 0.01 is converted into a single by the compiler may be evaluated to a single or an integer (I don't remember which) but in both cases the result would fit into both an integer or a single, so I don't see anything wrong with it. Then it's assigned to pvol.fVolume which is a single. Nothing wrong there.

Bass seems to have nothing to do with it.

If the overflow error is trapped by VB6 then one thing you can do to better spot the offending operation is to assign the result of the expression to a custom single and in another line assign that to pvol.fVolume. Something in the line of:

Dim tmp as Single

On Error Goto ErrLine1
line1: tmp = 0.01 * v
On Error Goto ErrLine2
line2: pvol.fVolume = tmp

ErrLine1:
Debug.Print "ErrLine1"
Exit Sub

ErrLine2:
Debug.Print "ErrLine2"
Exit Sub

This won't slow down you code so you can leave it in place forever.

You may also cast both operands to singles before multiplying them:
Csng (0.01) * Csng (v)

You may disable all the compiler optimizations (if you're using them), too, if your code isn't time critical.

Couin

Hi jpf,

Happy to see you there :)

Like you mentionned, it will difficult to catch the error, I got it only once, and no one else had reported it.

Perhaps something wrongly loaded?

About undocumented code, I have to check but as far as I remember, I think I not use this.

Also, I made changes for code like your wrote (one goto error for each line, and conversion to singles too). If the error come back, it will give some more precision :)

jpf

Sure, something "wrongly loaded" i.e. corrupted code has been more usual than advertised in my projects. Sometimes I was able to spot the mistake when it was in the source code. Other times just rebooting the PC solved the issue. I tend to blame the hardware. All the times this kind of errors happened to me, shortly after I got massive hardware failures.


Couin

Perhaps because of my PC is a quiet old (2011 lol), but I usualy have no problem with it. So for yth moment, I don't know.

About modified code, the console returns ErrLine1 but the error number is 0.

jpf

It seems you don't have a "Exit Sub" before your error handling lines. Your code should be like

' update volume
Public Sub UpdateVol(ByVal fxvol As Long, ByVal v As Integer)

Dim tmp as Single

On Error Goto ErrLine1
line1: tmp = 0.01 * v

On Error Goto ErrLine2
line2: pvol.fVolume = tmp

On Error GoTo Error_Routine
Call BASS_FXSetParameters(fxvol, pvol)

Exit_Routine:
Exit Sub

ErrLine1:
Debug.Print "ErrLine1"
Exit Sub

ErrLine2:
Debug.Print "ErrLine2"
Exit Sub

Error_Routine:
5        If err.Number <> 0 Then
6            Debug.Assert False
7            ErrorLog "modClick.UpdateVol"
8            Resume Exit_Routine
9        End If
End Sub

Waarning: I see a potential endless loop in your Error_Routine if ErrorLog raises an error.

Couin

Hi :)

You are right, with the Exuit Sub I no longer have the Error 0 :)

About potential loop, Resume Exit_Routine should send the pointer to the Exit_Routine step, where is following Exit Sub, it should prevent from endless loop (?).

jpf

You're right. I misread your code.
I'm glad that you got it to work.