maxmod program hangs after pressing a key

Post Reply
snoosdoot
Posts: 2
Joined: Tue May 07, 2019 7:48 pm

maxmod program hangs after pressing a key

Post by snoosdoot » Tue May 07, 2019 8:28 pm

read title

im sure what is wrong looks really obvious but im a noob so i dont see it

[mod edit: add code]

Code: Select all

#include <nds.h>
#include <maxmod9.h>
#include <stdio.h>

#include "soundbank.h"
#include "soundbank_bin.h"

int main() {

	consoleDemoInit();
	keyboardDemoInit();
	mmInitDefaultMem((mm_addr)soundbank_bin);
	int loadedsound = -1;
	// load the module
	//mmLoad( MOD_BB );

	// load sound effects

	// Start playing module
	//mmStart( MOD_BB, MM_PLAY_LOOP );
	
	while(1) {
		swiWaitForVBlank();
		scanKeys();
		int pressed = keysDown();
		//if(pressed & KEY_START) break;
		if(pressed & KEY_START){
			loadedsound = MOD_ENIGMA;
			printf("Key pressed");
			mmStop();
			if(loadedsound != -1) mmUnload(loadedsound);
			mmLoad(MOD_ENIGMA);
			mmStart(MOD_ENIGMA, MM_PLAY_LOOP);
		}
		if(pressed & KEY_SELECT){
			loadedsound = MOD_BB;
			printf("Key pressed");
			mmStop();
			if(loadedsound != -1) mmUnload(loadedsound);
			mmLoad(MOD_BB);
			mmStart(MOD_BB, MM_PLAY_LOOP);
		}
	}

}
https://www.dropbox.com/s/ytpemyssacgecdc/arm9.7z?dl=0 here's download

(press start or select to change song, also desmume doesnt detect the key presses so use melonds or real hardware)

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: maxmod program hangs after pressing a key

Post by WinterMute » Wed May 08, 2019 6:52 pm

I've edited your post to add the source code in question - for small chunks like this it can be easier to look at code in place rather than grabbin an archive & extracting it in order to compile locally.

The most immediately obvious problem is this :-

Code: Select all

			loadedsound = MOD_ENIGMA;
			printf("Key pressed");
			mmStop();
			if(loadedsound != -1) mmUnload(loadedsound);
			mmLoad(MOD_ENIGMA);
			mmStart(MOD_ENIGMA, MM_PLAY_LOOP);
You're setting loadedsound before you test it and therefore attempting to unload a module that isn't loaded. Ideally this shouldn't hang but it is clearly an error. You should set loadedsound after mmStart.

Any chunk of code that differs by only one parameter is also a good candidate for a separate function.
Help keep devkitPro toolchains free, Donate today

Personal Blog

snoosdoot
Posts: 2
Joined: Tue May 07, 2019 7:48 pm

Re: maxmod program hangs after pressing a key

Post by snoosdoot » Fri May 10, 2019 3:28 pm

WinterMute wrote: Wed May 08, 2019 6:52 pm I've edited your post to add the source code in question - for small chunks like this it can be easier to look at code in place rather than grabbin an archive & extracting it in order to compile locally.

The most immediately obvious problem is this :-

Code: Select all

			loadedsound = MOD_ENIGMA;
			printf("Key pressed");
			mmStop();
			if(loadedsound != -1) mmUnload(loadedsound);
			mmLoad(MOD_ENIGMA);
			mmStart(MOD_ENIGMA, MM_PLAY_LOOP);
You're setting loadedsound before you test it and therefore attempting to unload a module that isn't loaded. Ideally this shouldn't hang but it is clearly an error. You should set loadedsound after mmStart.

Any chunk of code that differs by only one parameter is also a good candidate for a separate function.
thanks :D it worked

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest