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

Hydrogen crashes when dragging an instrument #478

Closed
mauser opened this issue Feb 16, 2017 · 4 comments
Closed

Hydrogen crashes when dragging an instrument #478

mauser opened this issue Feb 16, 2017 · 4 comments
Labels

Comments

@mauser
Copy link
Member

mauser commented Feb 16, 2017

Hydrogen 0.9.7 crashes when a drag operation starts on the left side of the pattern editor and ends somewhere in the note area of the pattern editor.

Note: this seems to happen only if the drumkit has only two instruments.

@mauser mauser added the bug label Feb 23, 2017
@xnakos
Copy link
Contributor

xnakos commented Mar 2, 2017

It happens with more instruments too. Look at the following image:

bug

Drag any instrument and drop it over the blue area (the note area that corresponds to the penultimate instrument). You should easily crash hydrogen.

Also have in mind that dropping an instrument over places that are above the blue area will generally make the instrument go two places (in the instrument list) below where you dropped it.

In the case of the crash the "two places below" is a place beyond the instrument list / note area.

Why that happened.

PatternEditorInstrumentList::dropEvent(QDropEvent *event):

int nTargetInstrument = event->pos().y() / m_nGridHeight; will be calculated differently for dropping within the instrument list and within the note area. pos().y() will be 0 on the axes denoted by the red segments. When dropping within the blue area, this augmented Y value will make nTargetInstrument take the value of the exact size of the instrument list. The statement below:

if( nTargetInstrument > engine->getSong()->get_instrument_list()->size() ){
	nTargetInstrument = engine->getSong()->get_instrument_list()->size() - 1;
}

will not fix this, because it does not check for equality. >= would catch it and this will fix the bug (although dropping within the note area would still make the instrument fall two places below - should dropping be allowed within the instrument list only?).

Also look at:

void DrumPatternEditor::functionMoveInstrumentAction( int nSourceInstrument,  int nTargetInstrument )
{
		Hydrogen *engine = Hydrogen::get_instance();
		AudioEngine::get_instance()->lock( RIGHT_HERE );

		Song *pSong = engine->getSong();
		InstrumentList *pInstrumentList = pSong->get_instrument_list();

		if ( ( nTargetInstrument > (int)pInstrumentList->size() ) || ( nTargetInstrument < 0) ) {
			AudioEngine::get_instance()->unlock();
			return;
		}

		pInstrumentList->move( nSourceInstrument, nTargetInstrument );

nTargetInstrument > (int)pInstrumentList->size() does not check for equality too, so it passes through there as well, so when it reaches

void InstrumentList::move( int idx_a, int idx_b )
{
	assert( idx_a >= 0 && idx_a < __instruments.size() );
	assert( idx_b >= 0 && idx_b < __instruments.size() );

the second assertion fails.

@trebmuh
Copy link
Member

trebmuh commented Mar 2, 2017

Issue confirmed on a fresh git build (Debian Jessie stable).

@vladimir-kirillovskiy
Copy link
Contributor

I've added PR for this issue, please have a look at it - #516.
Thank you.

@mauser
Copy link
Member Author

mauser commented Jul 16, 2017

Fixed with #516. Thanks vlad!

@mauser mauser closed this as completed Jul 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants