VLF bugged?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
victorprosa
Posts: 37
Joined: Wed Jan 14, 2009 5:53 am

VLF bugged?

Post by victorprosa »

Hi all!

I've been working with VLF lib for a long time, and i have a lot of experience with it. I am creating an interface for a new homebrew of mine...
This is the first time that I create a mult-lang HB, then, i decided to use RCO importing, which is working like a charm...

But today, I remembered to create the error handler in case of not finding my custom RCO...
Then, I wrote this down:

Code: Select all

#include <psputility.h>

Code: Select all

		int lang;
		lang = vlfGuiGetLanguage&#40;&#41;;

		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_JAPANESE&#41;&#41;
		&#123;
			resources_error = "Unable to load resources!";
			resource_error_handler&#40;&#41;;
		&#125;
		else &#123;
		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH&#41;&#41;
		&#123;
			resources_error = "Unable to load resources!";
			resource_error_handler&#40;&#41;;
		&#125;
		else &#123;
		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_FRENCH&#41;&#41;
		&#123;
			resources_error = "Impossible de charger des ressources!";
			resource_error_handler&#40;&#41;;
		&#125;
		else &#123;
		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_SPANISH&#41;&#41;
		&#123;
			resources_error = "No se puede cargar los recursos!";
			resource_error_handler&#40;&#41;;
		&#125;
		else &#123;
		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_GERMAN&#41;&#41;
		&#123;
			resources_error = "Nicht in der Lage, Ressourcen zu laden!";
			resource_error_handler&#40;&#41;;
		&#125;
		else &#123;
		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_ITALIAN&#41;&#41;
		&#123;
			resources_error = "Impossibile caricare le risorse!";
			resource_error_handler&#40;&#41;;
		&#125;
		else &#123;
		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_DUTCH&#41;&#41;
		&#123;
			resources_error = "Kan middelen laden!";
			resource_error_handler&#40;&#41;;
		&#125;
		else &#123;
		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_PORTUGUESE&#41;&#41;
		&#123;
			resources_error = "Nao e possível carregar os recursos!";
			resource_error_handler&#40;&#41;;
		&#125;
		else &#123;
		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_RUSSIAN&#41;&#41;
		&#123;
			resources_error = "Unable to load resources!";
			resource_error_handler&#40;&#41;;
		&#125;
		else &#123;
		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_KOREAN&#41;&#41;
		&#123;
			resources_error = "Unable to load resources!";
			resource_error_handler&#40;&#41;;
		&#125;
		else &#123;
		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_CHINESE_TRADITIONAL&#41;&#41;
		&#123;
			resources_error = "Unable to load resources!";
			resource_error_handler&#40;&#41;;
		&#125;
		else &#123;
		if &#40;&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_CHINESE_SIMPLIFIED&#41;&#41;
		&#123;
			resources_error = "Unable to load resources!";
			resource_error_handler&#40;&#41;;
		&#125;
		&#125;&#125;&#125;&#125;&#125;&#125;&#125;&#125;&#125;&#125;&#125;

Code: Select all

int resource_error_handler&#40;&#41;
&#123;
	int err;	
	err = vlfGuiMessageDialog&#40;resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE&#41;;
	if &#40;&#40;err = VLF_MD_BACK&#41;&#41;
	&#123;
		sceKernelExitGame&#40;&#41;;
	&#125;
	
	return 0;
&#125;
It seemed to be fine!
As soon as the documents of the VLF Lib tells that vlfGuiGetLanguage(); must return the language...

But, for some strange reason, it is choosing the 2nd option all the time! No matter of what language it is, it does not identifies the PSP language and uses the message writen in the second option...
The only way to avoid this is giving an invalid lang ID as 1st option, in this case this option is choosed by the system...

Is anything wrong with my code?
Is anything wrong with the VLF lib?
Is there any solution/workaround?

PS: Tested in PSP 3000 with GEN-C (which also gives me that annoying "black-waves" bug...)
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Take a closer look at your if statements:

Code: Select all

&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_JAPANESE&#41;
You don't do comparisons, but assignments there. A common mistake, that can be avoided by writing like this:

Code: Select all

&#40;PSP_SYSTEMPARAM_LANGUAGE_JAPANESE == lang&#41;
If you ever forget to put the double = there, the compiler will yell at you with a compile time error, because you cannot assign to a constant value.

PS: For easier reading of the code, I recommend you just use a switch statement for the language checks. There are too many curly brackets in that code and the neverending list of closing brackets at the end just looks... strange. This way you also avoid the assignment problem in the check.
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Davee
Posts: 43
Joined: Mon Jun 22, 2009 3:58 am

Post by Davee »

Raphael wrote:Take a closer look at your if statements:

Code: Select all

&#40;lang = PSP_SYSTEMPARAM_LANGUAGE_JAPANESE&#41;
You don't do comparisons, but assignments there. A common mistake, that can be avoided by writing like this:

Code: Select all

&#40;PSP_SYSTEMPARAM_LANGUAGE_JAPANESE == lang&#41;
If you ever forget to put the double = there, the compiler will yell at you with a compile time error, because you cannot assign to a constant value.

PS: For easier reading of the code, I recommend you just use a switch statement for the language checks. There are too many curly brackets in that code and the neverending list of closing brackets at the end just looks... strange. This way you also avoid the assignment problem in the check.
Definately use a switch statement here, you'll also a minor performance boost as it won't need to do all the comparisons (for items in the lower area).
victorprosa
Posts: 37
Joined: Wed Jan 14, 2009 5:53 am

Post by victorprosa »

OMG, I can't believe that I forgot about the switch functions!

Thanks for your help guys!

Ahn, and the final code (much simpler):

Code: Select all

		int lang;
		char *resources_error;
		
		lang = vlfGuiGetLanguage&#40;&#41;; 	
		
		switch &#40;lang&#41;&#123;
	case 0&#58;
		resources_error = "Unable to load resources!"; 
		break;
	case 1&#58;
		resources_error = "Unable to load resources!"; 
		break;
	case 2&#58;
		resources_error = "Impossible de charger des ressources!"; 
		break;
	case 3&#58;
		resources_error = "No se puede cargar los recursos!"; 
		break;
	case 4&#58;
		resources_error = "Nicht in der Lage, Ressourcen zu laden!"; 
		break;
	case 5&#58;
		resources_error = "Impossibile caricare le risorse!";
		break;
	case 6&#58;
		resources_error = "Kan middelen laden!"; 
		break;
	case 7&#58;
		resources_error = "Nao e possivel carregar os recursos!"; 
		break;
	case 8&#58;
		resources_error = "Unable to load resources!"; 
		break;
	case 9&#58;
		resources_error = "Unable to load resources!"; 
		break;
	case 10&#58;
		resources_error = "Unable to load resources!"; 
		break;
	case 11&#58;
		resources_error = "Unable to load resources!";
		break;
	default&#58;
		resources_error = "Unable to load resources!";
&#125;

	int err;   
	err = vlfGuiMessageDialog&#40;resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE&#41;;
	if &#40;&#40;err = VLF_MD_BACK&#41;&#41;
	&#123;
		sceKernelExitGame&#40;&#41;;
	&#125; 
whistler
Posts: 39
Joined: Tue Mar 04, 2008 7:08 am

Post by whistler »

victorprosa wrote: int err;
err = vlfGuiMessageDialog(resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE);
if ((err = VLF_MD_BACK))
{
sceKernelExitGame();
} [/code]
once again, check your if statements
victorprosa
Posts: 37
Joined: Wed Jan 14, 2009 5:53 am

Post by victorprosa »

whistler wrote:
victorprosa wrote: int err;
err = vlfGuiMessageDialog(resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE);
if ((err = VLF_MD_BACK))
{
sceKernelExitGame();
} [/code]
once again, check your if statements
Sorry, if you want me to use

Code: Select all

VLF_MD_BACK == lang
But it don't works, and

Code: Select all

err = VLF_MD_BACK
does, without any warning at the compiler, block/bug/error at the PSP/PSPLink...
NoEffex
Posts: 106
Joined: Thu Nov 27, 2008 6:48 am

Post by NoEffex »

victorprosa wrote:
whistler wrote:
victorprosa wrote: int err;
err = vlfGuiMessageDialog(resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE);
if ((err = VLF_MD_BACK))
{
sceKernelExitGame();
} [/code]
once again, check your if statements
Sorry, if you want me to use

Code: Select all

VLF_MD_BACK == lang
But it don't works, and

Code: Select all

err = VLF_MD_BACK
does, without any warning at the compiler, block/bug/error at the PSP/PSPLink...
What

Code: Select all

if &#40;&#40;err = VLF_MD_BACK&#41;&#41;
	&#123;
		sceKernelExitGame&#40;&#41;;
	&#125; 
Basically does is

Code: Select all

err = VLF_MD_BACK;
if&#40;err > 0&#41;
&#123;
	sceKernelExitGame&#40;&#41;;
&#125;
Meaning, it will never change.
Programming with:
Geany + Latest PSPSDK from svn
willow :--)
Posts: 107
Joined: Sat Jan 13, 2007 11:50 am

Post by willow :--) »

How about some "Yagni" in your switch ?

Code: Select all

switch &#40;lang&#41;&#123;
   case 2&#58;
      resources_error = "Impossible de charger des ressources!";
      break;
   case 3&#58;
      resources_error = "No se puede cargar los recursos!";
      break;
   case 4&#58;
      resources_error = "Nicht in der Lage, Ressourcen zu laden!";
      break;
   case 5&#58;
      resources_error = "Impossibile caricare le risorse!";
      break;
   case 6&#58;
      resources_error = "Kan middelen laden!";
      break;
   case 7&#58;
      resources_error = "Nao e possivel carregar os recursos!";
      break;
   default&#58;
      resources_error = "Unable to load resources!";
&#125; 
The less code you have, the happier.
Unless you are just waiting for translations in those various cases, of course ;)
coyotebean
Posts: 18
Joined: Sat Dec 05, 2009 1:02 am

Post by coyotebean »

victorprosa wrote:
Sorry, if you want me to use

Code: Select all

VLF_MD_BACK == lang
But it don't works, and

Code: Select all

err = VLF_MD_BACK
does, without any warning at the compiler, block/bug/error at the PSP/PSPLink...
Please remember:
Single = is assignment.
Double == is comparison.

Also, if you have many messages, you may consider using resource array to hold the messages of different languages. Then you don't need so many messy switch/if statements and the code will look much nicer.
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

Well, it's not a psp related question but anyway.

Handling return's this way seems to be common :

Code: Select all

int err; 

err = vlfGuiMessageDialog&#40;resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE&#41;; 

if &#40; &#40; err == VLF_MD_BACK &#41; &#41; 
&#123; 
	sceKernelExitGame&#40;&#41;; 
&#125;
Is there a disadvantage to do that in this situation ?

Code: Select all

if &#40; vlfGuiMessageDialog&#40;resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE&#41; == VLF_MD_BACK &#41;
	sceKernelExitGame&#40;&#41;; 
From what i understand ( and this is where i'd like to know if i understand correctly ), the "int err" check would be only useful if i would like to check "err" to more than one error code ? Or is it useful/recommended to use it even for one check ?
Draan
Posts: 48
Joined: Sat Oct 17, 2009 3:39 am

Post by Draan »

you're wasting 4 bytes of memory here xD

Do as you whish, it doesn't really matter here
victorprosa
Posts: 37
Joined: Wed Jan 14, 2009 5:53 am

Post by victorprosa »

willow :--) wrote:How about some "Yagni" in your switch ?

Code: Select all

switch &#40;lang&#41;&#123;
   case 2&#58;
      resources_error = "Impossible de charger des ressources!";
      break;
   case 3&#58;
      resources_error = "No se puede cargar los recursos!";
      break;
   case 4&#58;
      resources_error = "Nicht in der Lage, Ressourcen zu laden!";
      break;
   case 5&#58;
      resources_error = "Impossibile caricare le risorse!";
      break;
   case 6&#58;
      resources_error = "Kan middelen laden!";
      break;
   case 7&#58;
      resources_error = "Nao e possivel carregar os recursos!";
      break;
   default&#58;
      resources_error = "Unable to load resources!";
&#125; 
The less code you have, the happier.
Unless you are just waiting for translations in those various cases, of course ;)
In truth, I am trying to find an easy way to write accents and jp/ch/kr/ru characaters, the traditional methods I used in golden times for DOS doesn't seems to work with the PSP...

----------------------------------------------------------------------------
coyotebean wrote:
victorprosa wrote:
Sorry, if you want me to use

Code: Select all

VLF_MD_BACK == lang
But it don't works, and

Code: Select all

err = VLF_MD_BACK
does, without any warning at the compiler, block/bug/error at the PSP/PSPLink...
Please remember:
Single = is assignment.
Double == is comparison.

Also, if you have many messages, you may consider using resource array to hold the messages of different languages. Then you don't need so many messy switch/if statements and the code will look much nicer.
As you can see in the main post, I am using this messy stuff just for the error handler in case of a missing RCO, resource stuff + xml is much easier handled by the VLF and much simpler in multlang...

------------------------------------------------

Anyway, thank you all for your help =]
Post Reply