Th0rstenf / Rocksniffer-to-Streamer.bot-extension

A set of streamerbot actions interacting with the Rocksmith RSSniffer
MIT License
6 stars 1 forks source link

Fix underflow in SaveNoteDataIfNecessary #78

Closed Th0rstenf closed 1 year ago

Th0rstenf commented 1 year ago
          Sorry, but still not ok!

image

Originally posted by @kozaka-tv in https://github.com/Th0rstenf/Rocksniffer-to-Streamer.bot-extension/issues/64#issuecomment-1498056820

Apparently underflows can still happen. Also resetting lastNoteData must only happen if it is certain a restart happened (resume seems to wind back the chart by roughly 2.x seconds

Th0rstenf commented 1 year ago

The more I think about it, I think that we should always reset lastNoteData when leaving pause. If resume rewinds by a few seconds, it would also potentially decrease the amount of notes in some cases, which then might lead to the underflow again.

However i'm not sure how the underflow still occured while lastNoteData was already set to currentNoteData.

Need to debug, but certainly don't find the time today anymore.

Th0rstenf commented 1 year ago

I can not reproduce the error behavior somehow. Neither in SB, nor in Debugger. Can you check with the latest state on this branch @kozaka-tv ?

Th0rstenf commented 1 year ago

The more I think about it, this error does not seem to be caused by that calculation.

Even the cases we've identified, do not cause overflow errors, as the type is signed. It's a perfectly legal operation, not violating the negative maximum.

Plus I can not reproduce the error at all (the behavior yes, but it doesn't throw an error)

Is it possible that you have any sideeffects with your pause actions, that deallocate SB resources? I've seen that happen, which lead to SetVar throwing errors as LiteSQL was no longer available to CPH

Th0rstenf commented 1 year ago

I tested the following code that is a minimum example of what we thought is causing the problem:

using System;

public class CPHInline
{
    public bool Execute()
    {

        int x = 0;
        int y = 1;
        int result = x - y;

        CPH.LogDebug($"x={x} - y={y} = {result}");
        // your main code goes here
        return true;
    }
}

The output:

[2023-04-09 13:34:57.186 DBG] ActionDispatcher :: Queueing 'test' (3ec3198b-a935-4e07-b209-0852bf1f7521) to 'Default' (00000000-0000-0000-0000-000000000000), with 6 arguments
[2023-04-09 13:34:57.188 DBG] ActionQueue :: 'Default' (00000000-0000-0000-0000-000000000000) :: Performing non-blocking 'test' (e709908b-b10f-4049-b115-c9da5d58d148), with 7 arguments
[2023-04-09 13:34:57.189 VRB] Action (e709908b-b10f-4049-b115-c9da5d58d148) :: Running 'test' => 'ExecuteCode'
[2023-04-09 13:34:57.189 DBG] InlineCode :: Running default entry point from instance 'c079eb37-e7c2-4736-b633-72a3813f1b48'
[2023-04-09 13:34:57.189 DBG] x=0 - y=1 = -1
[2023-04-09 13:34:57.189 VRB] Action (e709908b-b10f-4049-b115-c9da5d58d148) :: Completed 'test' => 'ExecuteCode' in 0,2723ms with result of 'True'
[2023-04-09 13:34:57.189 VRB] Action (e709908b-b10f-4049-b115-c9da5d58d148) :: Completed 'test' in 0,351ms with a result of 'True'
[2023-04-09 13:35:02.228 DBG] ActionDispatcher :: Queueing 'test' (3ec3198b-a935-4e07-b209-0852bf1f7521) to 'Default' (00000000-0000-0000-0000-000000000000), with 6 arguments
[2023-04-09 13:35:02.230 DBG] ActionQueue :: 'Default' (00000000-0000-0000-0000-000000000000) :: Performing non-blocking 'test' (edf33152-95bf-4f2b-a030-378da3857608), with 7 arguments
[2023-04-09 13:35:02.230 VRB] Action (edf33152-95bf-4f2b-a030-378da3857608) :: Running 'test' => 'ExecuteCode'
[2023-04-09 13:35:02.230 DBG] InlineCode :: Running default entry point from instance 'c079eb37-e7c2-4736-b633-72a3813f1b48'
[2023-04-09 13:35:02.230 DBG] x=0 - y=1 = -1
[2023-04-09 13:35:02.230 VRB] Action (edf33152-95bf-4f2b-a030-378da3857608) :: Completed 'test' => 'ExecuteCode' in 0,2446ms with result of 'True'
[2023-04-09 13:35:02.230 VRB] Action (edf33152-95bf-4f2b-a030-378da3857608) :: Completed 'test' in 0,3027ms with a result of 'True'

It's no chance that the issue is caused by the code arithmetic here. Do you happen to have any code in leavePause that might not be running cleanly @kozaka-tv ?