fix(vm/compiler/templates): modulating delaytime in wasm could crash

The modulated delay time was converted to int with i32.trunc_f32_u.
This throws runtime error if the modulations caused the delaytime
to become negative, because _u implied that it should be unsigned
integer and negative numbers were out of range. Using
i32.trunc_f32_s fixed this.
This commit is contained in:
5684185+vsariola@users.noreply.github.com 2024-04-08 20:06:20 +03:00
parent f074c392f6
commit 4a8d4c5a29
2 changed files with 4 additions and 2 deletions

View File

@ -29,6 +29,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
x87 stack. x87 stack.
### Fixed ### Fixed
- Modulating delaytime in wasm could crash, because delay time was converted to
int with i32.trunc_f32_u. Using i32.trunc_f32_s fixed this.
- When recording notes from VSTI, no track was created for instruments that had - When recording notes from VSTI, no track was created for instruments that had
no notes triggered, resulting in misalignment of the tracks from instruments. no notes triggered, resulting in misalignment of the tracks from instruments.
- 32-bit su_load_gmdls clobbered ebx, even though __stdcall demands it to be not - 32-bit su_load_gmdls clobbered ebx, even though __stdcall demands it to be not

View File

@ -313,7 +313,7 @@
)) ))
{{- end}} {{- end}}
{{- if .SupportsModulation "delay" "delaytime"}} {{- if .SupportsModulation "delay" "delaytime"}}
(i32.trunc_f32_u (f32.add (i32.trunc_f32_s (f32.add
(f32.add (f32.add
(local.get $delayTime) (local.get $delayTime)
(f32.mul (f32.mul
@ -324,7 +324,7 @@
(f32.const 0.5) (f32.const 0.5)
)) ))
{{- else}} {{- else}}
(i32.trunc_f32_u (f32.add (local.get $delayTime) (f32.const 0.5))) (i32.trunc_f32_s (f32.add (local.get $delayTime) (f32.const 0.5)))
{{- end}} {{- end}}
{{- else}} {{- else}}
(i32.load16_u (i32.load16_u