Homebrew Need help with what I think could be a ctrulib bug

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
I found a strange bug in all my homebrew in CIA format.

While in the homebrew, if I pres the home button the system opens the home menu, from here if I close the 3ds case and then open it again, both screens remain black and the system seems to be frozen.

It doesn't seems to be a problem in my code, but before opening an isuue on the ctrulib github I ask the devs of the forum to check it.

The problem happens with the following simple code too:

Code:
#include <stdio.h>

#include <3ds.h>

//----------------------------------------------------------------------------
int main(int argc, char **argv) {
//----------------------------------------------------------------------------

   PrintConsole topScreen;

   gfxInitDefault();

   consoleInit(GFX_TOP, &topScreen);

   consoleSelect(&topScreen);

   printf("Press START to exit\n");

   int i=0;
   while(aptMainLoop()) {

     gfxSwapBuffers();
     gfxFlushBuffers();
     gspWaitForVBlank();

     hidScanInput();
     u32 kDown = hidKeysDown();

     if (kDown & KEY_START)
       break; // break in order to return to hbmenu

   printf("%i\n",i++);

   }

   gfxExit();
   return 0;
}

You can find attached the rsf file I used for the test (UniqueId 0xffff that I use to test pre release cias)

Maybe it isn't a ctrulib problem but only of my CFW version (it's RXTool, I know it's outdated, but I use it only to test my hoembrew in CIA format)

If you have time please test this simple homebrew and tell me if the problem happens with your CFW and ctrulib version.

Thanks in advance. NOP90
 

Attachments

  • ciatest.zip
    2 KB · Views: 119

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,821
Trophies
2
Location
home
XP
9,317
Country
Hungary
I can confirm this is an issue! And I think I know why!

You see, ctrulib only processes APT events in aptMainLoop(), but if you are in the home menu, iirc the main thread gets suspended.
In official applications, APT events are handled by a separate thread which is NOT suspended when you suspend the application, meaning if you close the lid, and open it back, it's still handled by the application.

Also, this is both the 3DS's fault, and ctrulib's fault :P
 

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
So to solve ithis we could create in the app a separate thread that hadles the exiting from the sleep mode, and inserting a sleep() call in the aptmainloop() function to make run the second thread.

What about it?
 

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,821
Trophies
2
Location
home
XP
9,317
Country
Hungary
So to solve ithis we could create in the app a separate thread that hadles the exiting from the sleep mode, and inserting a sleep() call in the aptmainloop() function to make run the second thread.

What about it?

Well, ye, we could replicate how official apps do it, but if your app crashes, and you try to return to *hax, then it'll still run in the background, causing many troubles, so it doesn't sound like a good idea :/

I mean, technically we can detect if we're running as a .cia, so it should be possible to make or not make a thread for APT, depending on how you run the program.
 

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
After opening an issue on ctrulib github, Fincs informed me that this problem has been solved in ctrulib at the end of july, so updating ctrulib solves the problem.

I tested it and can confirm that now everything works fine.
 
  • Like
Reactions: hippy dave

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    SylverReZ @ SylverReZ: :rofl2: :rofl2: