gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Bugged Console behavior

#167508 - albinofrenchy - Mon Mar 16, 2009 6:10 am

Anyone else thing its a bug that if you initialize two consoles without passing in a PrintConsole parameter to either function, you get back the same pointer?

I just ran into this when switching back and forth between top and bottom screen consoles. I fixed it by creating my own consoles, but my libnds doesn't seem to have any functions to create new printconsoles, so I have things like this:

Code:

bottomConsole = (PrintConsole*)malloc(sizeof(PrintConsole));
memcpy(bottomConsole, consoleGetDefault(), sizeof(PrintConsole));
   
bottomConsole = consoleInit(bottomConsole, 1,BgType_Text4bpp ,
      BgSize_T_256x256, 0, 1, true, true);


Any better way to do this? Am I in the minority in thinking this is unexpected behavior?

#167509 - hacker013 - Mon Mar 16, 2009 8:34 am

yes it has function to create new consoles:

consoleInit(); and create just pointer to a printConsole struct and then you pass the through on the point where you normally consoleGetDefault passes.
_________________
Website / Blog

Let the nds be with you.

#167513 - elhobbs - Mon Mar 16, 2009 1:46 pm

albinofrenchy wrote:
Anyone else thing its a bug that if you initialize two consoles without passing in a PrintConsole parameter to either function, you get back the same pointer?

I just ran into this when switching back and forth between top and bottom screen consoles. I fixed it by creating my own consoles, but my libnds doesn't seem to have any functions to create new printconsoles, so I have things like this:

Code:

bottomConsole = (PrintConsole*)malloc(sizeof(PrintConsole));
memcpy(bottomConsole, consoleGetDefault(), sizeof(PrintConsole));
   
bottomConsole = consoleInit(bottomConsole, 1,BgType_Text4bpp ,
      BgSize_T_256x256, 0, 1, true, true);


Any better way to do this? Am I in the minority in thinking this is unexpected behavior?
I believe this behavior is by design. A PrintConsole contains the state information for a print context. In the main case there is typically only one console. So, when it is NULL for consoleInit the default console is assumed. returning the same console is there to handle returning the default console when a NULL PrintConsole is supplied. So you can either statically create space for a new PrintConsole or dynamically create one as you have above. I do not believe it is required to copy the default console into the dynamically created one as initConsole takes care of setting the structure up for you.

#167518 - albinofrenchy - Mon Mar 16, 2009 10:09 pm

Quote:
I do not believe it is required to copy the default console into the dynamically created one as initConsole takes care of setting the structure up for you.


I was wondering about this; I looked superficially at the code and it didn't seem to be setting everything; so I went ahead and am copying it out. I'll try it without the memcpy and see if it works still.

Quote:
In the main case there is typically only one console.


I'd think there would often times be two; one for the top and one for the bottom. I guess not though?

I actually don't get the point in having a default console if this is the behavior; might as well just handle allocation and pass back that pointer if they give you a null pointer. Sure, you'd have to free it, but if they are using only one console anyway, nothing would change.

#167521 - elhobbs - Tue Mar 17, 2009 12:29 am

the default console is statically declared with default values.