Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buzzmachines can receive "0" instrument number #80

Open
dlbeswick opened this issue Jul 25, 2019 · 7 comments
Open

Buzzmachines can receive "0" instrument number #80

dlbeswick opened this issue Jul 25, 2019 · 7 comments

Comments

@dlbeswick
Copy link
Contributor

Repro:

  • Add a Matilde Tracker machine without loading any samples
  • Place a note in the pattern such that no instrument number is shown in the track
  • Play song
  • Crash

From Matilde Tracker's source in the buzzmachines project, it seems to assume that it will never be asked to play an instrument with a number less than 1. In this case, it receives instrument 0 and it indexes an array with "instrument_num - 1", which overwrites pointer data in its class and causes a crash.

Other machines may be making similar assumptions. Should buzztrax ensure that machines will always get instrument numbers >= 1?

@ensonic
Copy link
Member

ensonic commented Jul 28, 2019

With 'instrument' do you mean 'wave' ? If you get a crash please get a backtrace. If you need help, maybe join the chat room
https://gitter.im/Buzztrax/buzztrax

I just tried it and did not get a crash.

@dlbeswick
Copy link
Contributor Author

I think I did mean wave, yes.

Does this song crash for you?

<?xml version="1.0"?> <buzztrax xmlns="http://www.buzztrax.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="buzztrax.xsd"><meta><name>crash-mt</name><author>David</author><create-dts>2019-07-28T11:42:27Z</create-dts><change-dts>2019-07-28T11:42:40Z</change-dts><bpm>125</bpm><tpb>4</tpb><bars>16</bars></meta><setup><properties><property key="selected-pattern" value="00"/><property key="selected-machine" value="Matilde-Tracker"/><property key="active-page" value="2"/></properties><machines><machine id="Matilde-Tracker" state="normal" type="source" plugin-name="bml-Matilde-Tracker" voices="1"><prefsdata name="children" value="1"/><prefsdata name="Volume-Ramp-ms" value="1"/><prefsdata name="Volume-Envelope-Span-ticks" value="64"/><prefsdata name="MIDI-Channel" value="0"/><prefsdata name="MIDI-Velocity-Sensitivity" value="0"/><prefsdata name="MIDI-Wave" value="0"/><prefsdata name="MIDI-Uses-Free-Tracks" value="0"/><prefsdata name="Filter-Mode" value="1"/><prefsdata name="Pitch-Envelope-Depth-semitones" value="2"/><prefsdata name="Enable-Virtual-Channels" value="0"/><voicedata voice="0" name="Wave" value="0"/><properties><property key="ypos" value="-0.021333333333333333"/><property key="xpos" value="0.36399999999999999"/></properties><patterns><pattern name="00" length="16"><tick time="0"><voicedata voice="0" name="Note" value="c-4"/></tick></pattern></patterns></machine><machine id="master" state="normal" type="sink"><prefsdata name="mode" value="0"/><prefsdata name="record-format" value="0"/><prefsdata name="record-file-name" value=""/><globaldata name="master-volume" value="1"/><properties><property key="ypos" value="0"/><property key="xpos" value="0"/></properties></machine></machines><wires><wire src="Matilde-Tracker" dst="master" gain="1" panorama="0"><wire-patterns/></wire></wires></setup><sequence length="64" tracks="1"><labels/><tracks><track index="0" machine="Matilde-Tracker"><position time="0" pattern="00"/></track></tracks></sequence><wavetable/></buzztrax>

@dlbeswick
Copy link
Contributor Author

dlbeswick commented Jul 28, 2019

Backtrace:

Thread 27 "Matilde-Tracker" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff955f9700 (LWP 9476)]
(gdb) bt
#0 0x0000000000000000 in ()
#1 0x00007fff96c4b8d3 in CTrack::NewNote(bool) (this=this@entry=0x555556bb16f8, oRetrig=oRetrig@entry=false) at ../../../Matilde/Tracker/Track.cpp:144
#2 0x00007fff96c4e422 in CTrack::Tick(CTrackVals&, CGlobalVals&) (this=this@entry=0x555556bb16f8, tv=..., gv=...) at ../../../Matilde/Tracker/Track.cpp:273
#3 0x00007fff96c4ee5e in CMachine::WorkMonoToStereo(float*, float*, int, int) (this=0x555556bae1b0, pin=, pout=0x7fff88013690, numsamples=256, mode=) at ../../../Matilde/Tracker/Tracker.cpp:543
#4 0x00007fff972924aa in gst_bml_src_create_stereo (base=, offset=, length=, buffer=0x7fff955f8928) at ../src/gst/bml/gstbmlsrc.c:708
#5 0x00007ffff7286069 in () at /usr/lib/x86_64-linux-gnu/libgstbase-1.0.so.0
#6 0x00007ffff7289278 in () at /usr/lib/x86_64-linux-gnu/libgstbase-1.0.so.0
#7 0x00007ffff6c1e139 in () at /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#8 0x00007ffff4b76b60 in () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#9 0x00007ffff4b76195 in () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#10 0x00007ffff48ea6db in start_thread (arg=0x7fff955f9700) at pthread_create.c:463
#11 0x00007ffff461388f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

@dlbeswick
Copy link
Contributor Author

I think that assuming wave 0 is given to Matilde Tracker, then the vtbl is being overridden on Matilde/Tracker/CTrack.cpp:134

m_pChannel->m_pInstrument=m_pMachine->m_Wavetable.GetInstrument( m_iInstrument );

@dlbeswick
Copy link
Contributor Author

This calls CWavetableManager::GetInstrument -- probably easier to look there.

@ensonic
Copy link
Member

ensonic commented Aug 10, 2019

Yeah, if I run:
GST_DEBUG="bt-core:5" gdb ./.libs/buzztrax-edit
I get

0:00:11.953144386 168950 0x555555980440 INFO                 bt-core src/lib/core/song.c:1082:bt_song_play: ->PLAYING needs async wait
0:00:11.976126085 168950 0x5555566156d0 DEBUG                bt-core src/lib/core/buzzcallbacks.c:63:GetWave: (0x7ffff7fd9540,0)
0:00:11.976153417 168950 0x5555566156d0 WARN                 bt-core src/lib/core/buzzcallbacks.c:91:GetWave: no wave for index 0

Thread 36 "Matilde-Tracker" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffc8c11700 (LWP 168994)]
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in  ()
#1  0x00007fffbb5e9401 in CTrack::NewNote(bool) (this=this@entry=0x555556ac5738, oRetrig=oRetrig@entry=false) at Track.cpp:142
#2  0x00007fffbb5ebf2a in CTrack::Tick(CTrackVals&, CGlobalVals&) (this=this@entry=0x555556ac5738, tv=..., gv=...) at Track.cpp:271
#3  0x00007fffbb5ec90a in CMachine::WorkMonoToStereo(float*, float*, int, int) (this=0x555556ac21f0, pin=<optimized out>, pout=0x7fffbc0151e0, numsamples=256, mode=<optimized out>) at Tracker.cpp:543
#4  0x00007fffd00af112 in gst_bml_src_create_stereo (base=0x5555568978c0, offset=<optimized out>, length=<optimized out>, buffer=0x7fffc8c10928) at src/gst/bml/gstbmlsrc.c:708
#5  0x00007ffff5eb80c9 in  () at /usr/lib/x86_64-linux-gnu/libgstbase-1.0.so.0
#6  0x00007ffff5ebb2d8 in  () at /usr/lib/x86_64-linux-gnu/libgstbase-1.0.so.0
#7  0x00007ffff5663349 in  () at /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#8  0x00007fffef97be30 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#9  0x00007fffef97b465 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#10 0x00007ffff7014c73 in start_thread (arg=<optimized out>) at pthread_create.c:486
#11 0x00007fffef436def in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

We should probably change the wavetable to return a built-in silence buffer as a fallback. I'll give it a shot.

@ensonic
Copy link
Member

ensonic commented Aug 10, 2019

I'll need to test in buzz (in my windows vm what the behavior is when requesting wavelevels (pCB->GetNearestWaveLevel() ) and having no wave loaded.
I currently return a wavelevel with length=0 (and nullptr for the sample data).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants