Author Topic: MidiFilterProc throws an AccessViolationException in BASSMIDI x86 (BASS.NET 2.4)  (Read 3437 times)

Ian @ un4seen

  • Administrator
  • Posts: 21208
Thanks. The latest LOG file seems to confirm that the stack is indeed getting corrupted in the MIDIFILTERPROC call. What is that function doing currently? If it isn't doing nothing then please try that, ie. this:

Code: [Select]
        public static bool MidiFilterProc(int handle, int track, BASS_MIDI_EVENT midievent, bool seeking, IntPtr user)
        {
            return true; // process the event
        }

KaleidonKep99

  • Posts: 179
It is just returning true, since you asked me to remove everything from it.
I still find weird how it happens on the x86 version of KMC only, the x64 one isn't affected.

Ian @ un4seen

  • Administrator
  • Posts: 21208
I guess it's possible that the stack is getting corrupted in 64-bit too but it just happens to not touch anything critical. I'm not a .Net user myself, so I've asked the BASS.Net developer if they have any thoughts on this.

radio42

  • Posts: 4625
I just made a quick test, but couldn't reproduce the issue.
Can you maybe provide a very simple test app (incl. the source) to try to reproduce it.

KaleidonKep99

  • Posts: 179
I just made a quick test, but couldn't reproduce the issue.
Can you maybe provide a very simple test app (incl. the source) to try to reproduce it.
The latest version of Keppy's MIDI Converter is affected, and it's hosted on GitHub.
The source code is also available.

If that's not enough, I could share a specific version of both the source code and compiled executable.

radio42

  • Posts: 4625
I donít know how to test this midi converter!
So some instructions would be needed!

Also have all versions be effected all the time (since forever)?
Or did the problem just recently started, eg. only with the latest version?

KaleidonKep99

  • Posts: 179
I donít know how to test this midi converter!
So some instructions would be needed!

Also have all versions be effected all the time (since forever)?
Or did the problem just recently started, eg. only with the latest version?
Oops sorry!

It started having this issue ever since I added the "Ignore notes within two velocity values" feature, in KMC 18.1.0.
I never bothered testing the feature in the x86 release until version 18.2.4 though, when I wanted to test a x86 VST (which shares MidiFilterProc with the feature from 18.1.0).

Here's how to reproduce the issue:
1. Open KMC
2. Either check "Show ignore tracks dialog before export" in the "Options" menu, or "Ignore notes in between two velocity values" in the advanced settings (Open settings)
3. Convert a MIDI

KMC will then crash. (Ignore anything about BASS_ERROR_ILLPARAM, it's just a check I do, but it doesn't trigger any error)

radio42

  • Posts: 4625
I am currently on holiday, so I will need to find some time ;-)
How do I Convert a midi?
Do i need a certain midi file or soundfont?

Was your 18.1.0 Version the first version where you ever used a MidiFilterProc?
Or have you used a MidiFilterProc also before?

KaleidonKep99

  • Posts: 179
I am currently on holiday, so I will need to find some time ;-)
How do I Convert a midi?
Do i need a certain midi file or soundfont?

Was your 18.1.0 Version the first version where you ever used a MidiFilterProc?
Or have you used a MidiFilterProc also before?
Don't worry, take your time. :P

Just add a MIDI to the conversion list (It happens with all the MIDIs), then enable one of the two functions I mentioned in my previous message, and KMC x86 will crash.
There's also no need for a SoundFont, since KMC ships with a generic one. Oh and the generic SoundFont isn't the issue either.

Yes, 18.1.0 was the first version using MidiFilterProc.


radio42

  • Posts: 4625
Sorry for the delay. But I can now clearly reproduce the issue here.
I have written a small 32-bit test app and have send it to Ian for further testing.
I do also believe, that there must be an issue in the 32bit version of bassmidi.dll.

Here is the rough code:
Code: [Select]
private Un4seen.Bass.AddOn.Midi.MIDIFILTERPROC _midiFilterProc = null;

private void TestMidi()
{
    _midiFilterProc = new Un4seen.Bass.AddOn.Midi.MIDIFILTERPROC(MidiFilterProc);

    int midiStream = Un4seen.Bass.AddOn.Midi.BassMidi.BASS_MIDI_StreamCreateFile(@"C:\Temp\test.mid", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT, 44100);

    if (Un4seen.Bass.AddOn.Midi.BassMidi.BASS_MIDI_StreamSetFilter(midiStream, true, _midiFilterProc, IntPtr.Zero)
    {
        Un4seen.Bass.Bass.BASS_ChannelPlay(midiStream);
    }
}

public static bool MidiFilterProc(int handle, int track, Un4seen.Bass.AddOn.Midi.BASS_MIDI_EVENT midievent, bool seeking, IntPtr user)
{
    return true; // process the event
}
As the Bass.Net is compiled for AnyCPU, there is also no difference between x86 and x64.
It does NEVER crash with in 64-bit, but only with the 32-bit version.
« Last Edit: 15 Oct '18 - 12:54 by radio42 »

radio42

  • Posts: 4625
The new BASS.NET v2.4.13.3 should fix the issue (with the help of Ian we could narrow down a marshaling issue, which is now fixed).

Greets,
Bernd

KaleidonKep99

  • Posts: 179
Sorry for being late! I've been busy fixing some issues on my MIDI driver! ;D ;D
I tested the latest BASS.NET release, and now the MidiFilterProc works great on the x86 release of KMC!

Thank you guys so much! :D