Page 1 of 1

libnds: Early read of X Key input and memset issue.

Posted: Tue Jan 06, 2009 4:41 pm
by Sylus101
Running this quick program displays the text shown without the key held. Tested in no$gba (text shows twice) and on hardware (text shows once). Same occurs with KEY_Y and KEY_TOUCH.

Code: Select all

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

int main(void) {

consoleDemoInit();

	while(1){
	
		scanKeys();
	
		if(keysHeld() & KEY_X)
			iprintf("This shouldn't show up");
		
		swiWaitForVBlank();
	}

	return 0;
}
EDIT - I also ran across something else, usage of memset on lines 161 and 188 of background.c are:

Code: Select all

memset(&bgState[layer], sizeof(BgState), 0); //line 161
//and
memset(&bgState[layer + 4], sizeof(BgState), 0); //line 188
Should be:

Code: Select all

memset(&bgState[layer], 0, sizeof(BgState)); //line 161
//and
memset(&bgState[layer + 4], 0, sizeof(BgState)); //line 188

Re: libnds: Early read of X Key input and memset issue.

Posted: Wed Jan 14, 2009 1:58 pm
by ambient_enigma
I had a similar problem that was solved by removing the following lines:

irqInit();
irqEnable(IRQ_VBLANK);

The problem went away after that. Hopefully that will help you, even though I
don't see those lines in your code.
You can see my original post under devkitARM on the index page in the post
"X,Y buttons and Touch Screen Unresponsive in New devkitARM"

Re: libnds: Early read of X Key input and memset issue.

Posted: Wed Jan 14, 2009 4:43 pm
by Sylus101
Yea, those lines aren't in there. It was posted on the main site when 1.3.1 came out that those lines would need to be removed as it's being done beforehand.

Still, it surely happens just with what I've got here... hoping someone can duplicate as well and verify.

Re: libnds: Early read of X Key input and memset issue.

Posted: Sat Jan 17, 2009 7:04 pm
by afireohno
Sylus, I ran into the same problem and after a great deal of frustration and trying random solutions got something to work. I'm not sure why, and it is definitely far from an elegant solution.

Code: Select all

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

int main() 
{		
	consoleDemoInit();	
	for (int i = 0; i <2; i++)
	{
		swiWaitForVBlank(); //wait 2 or more (tested up to 10)
	}
	
	int test = 0;
	while(1) {		
		scanKeys();		
		if(keysHeld() & KEY_X)
		{
			test = 1;
		}
		swiWaitForVBlank();
		consoleClear();		
		printf("test = %i",test);		
	}
	return 0;
}
Like I said I have no idea why, but it seems to work. Thoughts anyone?