PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

A kind of bug?

I found interesting thing about ButtonUp/ButtonDown functions. When I declare file and filebuffer in the same class where Button func is declared, and then open file like this:
--------------------------
loop_script_f = fopen(GetPath("resource\\loop_script.txt", path), "rb");
loop_script_size = fread(loop_script, sizeof(char), LUAL_BUFFERSIZE, loop_script_f);
--------------------------
and when I press any button, whole buffer contents becomes totaly destroyed. I wonder if that should be.
Sounds like a bad pointer.

Shouldn't you be using TCHAR and associated functions?(if you're compiling for both pc/ppc)
Maybe I should (I will try), but there is no need to since LUA works with char only. Pressing buttons spoils buffer content only on PPC, and works ok on PC. If I don't press any button (and until), all works fine both on PPC and PC. And most curious, moving loop_script buffer declaration to another class solve this problem...

That what I found about fread(): "This function locks out other threads. If you need a non-locking version, use _fread_nolock."
Isn't the PPC is unicode only? no single byte char. Must use all the TCHAR stuff. Do a search here.
As I told, when I make char buffer to be a member of another class, problem has gone, so I doubt there is any problem with TCHAR.
What do you meen by saying PPC is unicode only? Can I use simple char arrays then? (To say the true, I use char whenever it possible, and has no problem with it yet.)
And I wander why it's only ButtonUp/Button down events spoil the buffer, and stylus taps, for example, don't.
Anonymous wrote:As I told, when I make char buffer to be a member of another class, problem has gone, so I doubt there is any problem with TCHAR.
What do you meen by saying PPC is unicode only? Can I use simple char arrays then?

You can of course use char arrays or byte arrays as long as you want.. But you can't do much of them. All functions like sprintf, fread, strcmp, strlen - they just don't exist on PPC. As long as you don't write your own.


(To say the true, I use char whenever it possible, and has no problem with it yet.)
And I wander why it's only ButtonUp/Button down events spoil the buffer, and stylus taps, for example, don't.

It's probably the sign of memory being spoiled somewhere. No good. You can escape this bug now like this, but you may regret it later.

PS: Do you actually NEED lua? I tried using it, but finally realized that it's pretty much useless. As long as C++ doesn't have reflections and even if it had, i'm not sure.
It might have been of some use if we had 15 people working on the same project, but it's merely impossible.[/quote]
Could you be running out of stack?

Is loop_script allocated with malloc or just declared?


Also, I tried compiling the 'luacelib' from the package from http://www.uoam.net/lua.html and I do see some compiler messages that look like problems.
Code:

... warning C4133: 'function' : incompatible types - from 'char [128]' to 'unsigned short *'
... warning C4133: 'function' : incompatible types - from 'const char *' to 'const unsigned short *'
... warning C4133: 'function' : incompatible types - from 'const char *' to 'const unsigned short *'


One of those, for instance, is
Code:

HINSTANCE lib=LoadLibrary(path);


in the above code, path is a char array. LoadLibrary takes a LPCTSTR (a wide char on the PPC). I would thing that would fail if it is run, but who knows. Maybe the functions feeding are actually using wide char.

Can you compile that without errors? Maybe I'm missing something.
Anonymous wrote:
What do you meen by saying PPC is unicode only? Can I use simple char arrays then? (To say the true, I use char whenever it possible, and has no problem with it


Well, in my game I use char whenever possible, even to store the string that could be one of the 10 languages (4 windows codepages). I store the string and it's codepage in one class.

Of course the char could be used on PPC without a problem. All functions like sprintf, fread, strcmp, strlen are char functions, and they are still char on PPC (for wide characters strcmp would be wcscmp or _tcscmp macros (for PPC->wide char, PC->char)).

I had no single problem using chars, but sure, when opening a file from location, you'll need to use (not the best code):

Code:


#ifdef UNDER_CE
TCHAR tTemp[255];
mbstowcs(tTemp, BHistory[k].GetText(), 254);
G_scenario_name.Cpy(tTemp);
#else
G_scenario_name.Cpy(BHistory[k].GetText());
#endif


Using TCHAR macros and it's macros functions is of course much more simple, but sure there is size and speed penalty.

As for LUA, maybe it's good to see what differences are in ported (even old) PPC version and the recent PC version (unported one).
And that way to find and fix all widechar->char->widechar conversion issues.

P.S. And what I found important is to be sure to store the original paths in wchars or the Japaneese (and like) friends wouldn't have the ability to play your game (the files wouldn't be loaded) ;)
It's a unicode wide character device. Your char's on a PC would take a byte and on PPC 2, that's why if you write an app to run on PC as well the whole thing has to work using TCHAR and all the _t macros. If you do not run your app on PC (excluding in the emulator) then you won't see this issue but if like me you want your game to run on pc for testing or otherwise you use the TCHAR approach.

Happy to supply code samples.
I only wish they had more "intuitive" macros in tchar.h. I'm always forgeting these strange _stprintf, _tcsncpy etc.
Conan wrote:Your char's on a PC would take a byte and on PPC 2, that's why if you write an app to run on PC as well the whole thing has to work using TCHAR and all the _t macros.


char (variable type) is one byte variable on both PC and PPC, it's used for ASCII character set so why it's one byte on both.

tchar and it's functions is a macros, it's replaced to char (1 byte) on PC and to wchar_t (2 bytes) on PPC.

wide characters(unicode) on PPC is good when you handle paths, so you ensure that you can easily open and show the file even if the path and text in it is written in Japanese.
As to LUA, I compiled it with the same warnings to, but it works fine, and opening libraries cause no errors.
I agree where is not much use in LUA for action games, or any game with predefined rules. But for RPG, RTS games I see no way to escape of using some scripting language (not impotant LUA).
Forget to log in :lol: