Welcome! Log In Create A New Profile

Advanced

LibWiiGui: Displaying Changing Numbers

Posted by profetylen 
LibWiiGui: Displaying Changing Numbers
May 12, 2009 01:12AM
What I try to do:

Display a number which is changing all the time.

What I have tried:

I have tried using
sprintf(pData,"%d",(short) ir.y);
headlineText.SetText(pData);

and a bunch of other variants of the previous, but my wii always crashes and give me a code dump.
What do I do wrong?

pData is of type char*
and headlineText is a GuiText object.



Edited 1 time(s). Last edit at 05/12/2009 10:35AM by profetylen.
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 01:24AM
how are you declaring pData? you either have to do something like: char pData[20] or char * pData = (char *)malloc(20);

Also what cast that as a short? It's a float, you can just do sprintf(pData,"%.2f", ir.y);
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 10:52AM
Previously I declared pData like this:

char data;
char* pdaTa = &data;

Now, I do as you told me to:

char pData[20];

However, I am still getting crashes and code dumps as fast as I call SetText(pData);
This only happens when SetText(pData); is in the main while(1) loop.
When I put it outside the loop there's no crashes, but then, as you can tell, the number is never updated.

I changed to sprintf(pData,"%.2f", ir.y). Thanks for the tip! Previously it gave me errors because I didn't specify precision i think (that's why I casted it to short).
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 11:48AM
Are you trying to declare char pData[20] inside the loop ?
Try declaring char pData[20] outside the while loop then set it inside the loop with sprintf() and do some SetText(pData).
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 12:13PM
No I'm declaring pData outside the loop.

Then I call the other functions.

Like this:

char pData[20];
while(1)
{
       sprintf(pData,"%.2f",ir,y);
       headlineText.SetText(pData);
       .
       .
       .
       if(something)
       {
              break;
       }
}
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 12:28PM
Perhaps you could try to halt the GUI thread before updating the GuiText.
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 12:44PM
Yes, that worked!!

But, how do I know for what changes the GUI should be halted?
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 01:11PM
Hmm... I just noticed, when I use the method of halting and resuming the GUI, the program stops responding to buttons being pressed/released/held.

How can this happen?
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 01:22PM
Hmm... I just noticed, when I use the method of halting and resuming the GUI, the program stops responding to buttons being pressed/released/held.
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 02:31PM
Any change to a GuiElement (ie. any Gui* object) requires to halt the GUI thread because libwiigui does not use locks. (Accessing an element with the drawing thread while modifing it using the main thread causes a crash.).
So, you need to halt before Append() or any method that makes changes to object attributes like SetText or SetPosition ... etc.

Now your buttons stop responding after resuming the drawing thread...
Do they stop responding just between halt & resume or stay unresponsive forever once you've done a halt/resume ?
Did you try the GuiButton::ResetState() method after resuming ?
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 04:05PM
They stay unresponsive forever.

It's not Gui buttons. It's the buttons on the wiimote (aka Home, A, Right, Left etc).
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 04:34PM
Hmm... I'm starting maybe to realize now... Since i use libwiigui should I handle inputs somehow with GuiTrigger?
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 04:51PM
How do you handle your Home/A/etc... wiimote buttons in your while {} loop ?
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 04:56PM
Yeah ! you probably should ...
Make a fake "clickable" GuiButton (1x1 with no GuiImage, outside of the screen), bind a GuiTrigger::SetButtonOnlyTrigger on it, add it to your dialog and then test it like any other in the while(1) { } loop.
GuiButton::ResetState() will then "re-enable" locked buttons if you need them more than once in the while loop.

Don't know if it is the smartest way to do that but it works.



Edited 1 time(s). Last edit at 05/12/2009 05:00PM by Luckii.
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 04:57PM
Like this:

while(1)
{
	WPAD_ScanPads();
	u32 pressed = WPAD_ButtonsDown(0);

	if (pressed & WPAD_BUTTON_HOME)
	{
		break;
	}
}
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 05:00PM
OK!

I'll try that. But I'd sure like to understand why the thing I just tried worked when I didn't use halt and resume the GUI.

Thanks for all the help anyways! It has been really... helpful :)
Re: LibWiiGui: Displaying Changing Numbers
May 12, 2009 05:35PM
You're welcome
Sorry, only registered users may post in this forum.

Click here to login