Game behaves strangely in the DS

Post Reply
Ideka
Posts: 5
Joined: Wed Sep 07, 2011 4:31 am

Game behaves strangely in the DS

Post by Ideka » Wed Sep 07, 2011 5:10 am

I've been working on a small "engine" in C++ for developing purely text-based games (for the NDS using libnds, of course).

This is how the engine currently looks like in an emulator: http://i111.photobucket.com/albums/n147/IDKAA/e.png
The ">" sign can be moved around (and changes into a "<", "^" or "v" according to the direction it's "facing"), and the "/" symbols are "animated" (they rotate "/", "-", "\", "|", etc).
And it works pretty well.

On a real DS however, it looks like this: http://i111.photobucket.com/albums/n147/IDKAA/r.jpg
Well, the image isn't what I'd call "high quality", so...
Basically it works perfectly. except that a bunch of blinking smileys and strange symbols appear at the bottom center of the screen.

And... I can't figure out why this happens.
Well, I AM using consoleDemoInit and using cout to print stuff to the screen, and that's probably a bad idea. But I'm not sure that's the problem, and I'm new to libnds so I know no alternatives.

What can I do? Can someone point me in the rigth direction?
Thanks!

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

Re: Game behaves strangely in the DS

Post by WinterMute » Wed Sep 07, 2011 10:23 am

There's not really a lot we can do to help without at least seeing the nds file and preferably the actual code.

If you have the time and the inclination then IRC might be the best way to get help. See the link in my sig
Help keep devkitPro toolchains free, Donate today

Personal Blog

Ideka
Posts: 5
Joined: Wed Sep 07, 2011 4:31 am

Re: Game behaves strangely in the DS

Post by Ideka » Wed Sep 07, 2011 4:44 pm


Ideka
Posts: 5
Joined: Wed Sep 07, 2011 4:31 am

Re: Game behaves strangely in the DS

Post by Ideka » Tue Sep 13, 2011 6:16 am

Well, I could finally get it fixed. It seems both Nocash and DeSmuMe initialize to 0 (i.e. NULL) the memory they reserve for the rom being played. Or maybe they don't, what the hell I have no idea what I'm talking about.

What I do know is that the problem was in image.cpp, here:

Code: Select all

void Image::initialize(const char* repr[]) {
    transparent_char = '\0';
    vector<char> line;
    for (unsigned int i = 0; i < strlen(repr[0]); i++) {
        line.clear();
        for (unsigned int j = 0; repr[j][i] != NULL; j++) {
            line.push_back(repr[j][i]);
        }
        data.push_back(line);
    }
}
More specifically, in the condition of the second for.
Anyway, I'd explain what I think the cause was but I'm tired and I don't think much people care ;).
I'll just say that to fix it I switched from const char*[] to vector<string>:

Code: Select all

void Image::init(vector<string> repr) {
    transparent_char = '\0';
    vector<char> line;
    for (unsigned int i = 0; i < repr[0].size(); i++) {
        line.clear();
        for (unsigned int j = 0; j < repr.size(); j++) {
            line.push_back(repr[j][i]);
        }
        data.push_back(line);
    }
}
(Of course I had to change other stuff accordingly.)

Thanks to the people who took a look at the code. :)

mtheall
Posts: 210
Joined: Thu Feb 03, 2011 10:47 pm

Re: Game behaves strangely in the DS

Post by mtheall » Tue Sep 13, 2011 3:31 pm

This sounds like a classic case of "I forgot to initialize my data." If anything, it's the first for loop's condition that doesn't make sense; you don't usually check strlen on an array of char pointers. First, strlen was specifically made for char arrays. Second, it checks byte-by-byte until it reaches a byte that has the value '0'. Each index in the array of char pointers is the size of an int, so really you should have been checking int-by-int, not byte-by-byte, since it could stop early if one of the bytes in an address happened to be '0'. But that's still not a good way to find the size of an array, unless you specifically allocated an extra space for a NULL pointer at the end.

Actually, now that I'm looking at it, your two samples of code are opposite of each other. The inner/outer loops are swapped between them. This may be the original source of your problem (or it could just be compounding it).

mtheall
Posts: 210
Joined: Thu Feb 03, 2011 10:47 pm

Re: Game behaves strangely in the DS

Post by mtheall » Tue Sep 13, 2011 10:44 pm

whoops, my bad. Ignore what I said about the strlen stuff; you were doing it right. This code is very confusing. It would probably make sense to me with more context.

Ideka
Posts: 5
Joined: Wed Sep 07, 2011 4:31 am

Re: Game behaves strangely in the DS

Post by Ideka » Thu Sep 15, 2011 12:38 am

mtheall wrote:This code is very confusing. It would probably make sense to me with more context.
What do you mean? =o

mtheall
Posts: 210
Joined: Thu Feb 03, 2011 10:47 pm

Re: Game behaves strangely in the DS

Post by mtheall » Thu Sep 15, 2011 3:39 am

What I mean is that I haven't looked at the rest of the code you posted, and without that context, I'm unsure what you're trying to accomplish with the snippet in your previous post. It looks like you're trying to store the data for an image in an vector of strings, which, honestly, seems like a very inflated way of doing it.

Ideka
Posts: 5
Joined: Wed Sep 07, 2011 4:31 am

Re: Game behaves strangely in the DS

Post by Ideka » Sun Sep 18, 2011 6:18 pm

Well, as I said, the program is purely text-based, so "images" are actually made of characters.

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests