Comments (9)
Could you paste your test code? Thanks.
from libctru.
Sure, here's the contents of main.cpp.
#include <stdlib.h>
#include <string.h>
#include <string>
using namespace std;
#include <3ds.h>
Result http_download(httpcContext *context)//This error handling needs updated with proper text printing once ctrulib itself supports that.
{
Result ret=0;
u8* framebuf_top, *framebuf_bottom;
u32 statuscode=0;
u32 size=0, contentsize=0;
u8 *buf;
framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
memset(framebuf_bottom, 0x40, 240*320*3);
gfxFlushBuffers();
gfxSwapBuffers();
framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
memset(framebuf_bottom, 0x40, 240*320*3);
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();
ret = httpcBeginRequest(context);
if(ret!=0)return ret;
ret = httpcGetResponseStatusCode(context, &statuscode, 0);
if(ret!=0)return ret;
if(statuscode!=200)return -2;
ret=httpcGetDownloadSizeState(context, NULL, &contentsize);
if(ret!=0)return ret;
buf = (u8*)malloc(contentsize);
if(buf==NULL)return -1;
memset(buf, 0, contentsize);
framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
memset(framebuf_bottom, 0xc0, 240*320*3);
gfxFlushBuffers();
gfxSwapBuffers();
framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
memset(framebuf_bottom, 0xc0, 240*320*3);
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();
framebuf_top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
ret = httpcDownloadData(context, buf, contentsize, NULL);
if(ret!=0)
{
free(buf);
return ret;
}
size = contentsize;
if(size>(240*400*3))size = 240*400*3;
memset(framebuf_bottom, 0xff, 240*320*3);
memcpy(framebuf_top, buf + 8, size - 8); //skip past the width/height markers
gfxFlushBuffers();
gfxSwapBuffers();
framebuf_top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
memset(framebuf_bottom, 0xff, 240*320*3);
memcpy(framebuf_top, buf + 8, size - 8);
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();
free(buf);
return 0;
}
void display_image(u8* data, int size) {
u8* framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
memcpy(framebuf_bottom, data + 8, size - 8); //skip past the width/height markers
}
void download_and_display_image(string url) {
//debug_message("Attempting to download: " + url);
Result ret=0;
httpcContext context;
ret = httpcOpenContext(&context, (char*)url.c_str(), 0);//Change this to your own URL.
if(ret==0)
{
ret=http_download(&context);
httpcCloseContext(&context);
}
}
int main()
{
// Initialize services
srvInit();
aptInit();
hidInit(NULL);
gfxInit();
//gfxSet3D(true); // uncomment if using stereoscopic 3D
httpcInit();
string image_list[3] = {"http://darknovagames.com:1337/3ds/raw1.bin","http://darknovagames.com:1337/3ds/raw2.bin","http://darknovagames.com:1337/3ds/raw3.bin"};
int current_image = 0;
// Main loop
while (aptMainLoop())
{
gspWaitForVBlank();
hidScanInput();
// Your code goes here
u32 kDown = hidKeysDown();
if (kDown & KEY_START) {
break; // break in order to return to hbmenu
}
if (kDown & KEY_A) {
//download an image!
download_and_display_image(image_list[current_image]);
current_image++;
current_image = current_image % 3;
}
// Flush and swap framebuffers
gfxFlushBuffers();
gfxSwapBuffers();
}
// Exit services
httpcExit();
gfxExit();
hidExit();
aptExit();
srvExit();
return 0;
}
from libctru.
This is confirmed fixed on my end.
from libctru.
It seems to me that this has not been fixed yet: filiphsandstrom/DownloadMii-3DS#24
Looks like everyone is experiencing this; I get return code -660561894 (0xd8a0a01a) when calling httpcOpenContext
the 9th+ time.
@zeta0134's modified example app doesn't work properly either for me, so I'm not sure what's going on. I'm using Ninjhax 1.1 (3DS XL, 9.2.0-20E), and the latest libctru commit (9fec42f).
from libctru.
Are you absolutely sure that you're using the latest libctru? @zeta0134's test code is working perfectly for me on the same setup with this patch (Ninjhax 1.1, 3DS XL, 9.2.0-20E). Is there some other version of that code that's failing?
from libctru.
Also can you check return value of every single httpcCloseContext? Maybe your code is leaking contexts.
from libctru.
Read my comment again.
from libctru.
It always closes with code 0 on my build, I assume that's what's supposed to happen?
Also, now that I'm getting the return codes from httpcCloseContext
, for some reason the ninth httpcOpenContext
doesn't even return anything; it simply freezes the 3DS (how that's related to storing that return value I have no idea). No problems running the apps in 3dmoo, except these messages when calling httpcCloseContext
:
>> svcSendSyncRequest (0x32)
http_c_SyncRequest (line 217): CloseContext 0dadbb2a --stub--
>> svcCloseHandle (0x23)
svcCloseHandle: svcCloseHandle undefined for handle-type "service".
from libctru.
@filfat Me too. httpcCloseContext() can fail (return non-zero) and thus leak handles.
@celcodioc Yeah, that's correct. Sounds like you might be leaking something/somewhere else. Maybe you could modify 3dmoo to verify that all handles are closed/cleaned up correctly.
from libctru.
Related Issues (20)
- Performance issue in font.c HOT 5
- sys/lock.h: No such file or directory HOT 3
- GDB Debugging Issue: using 'c' and then pressing CTRL + C in GDB points to wrong file HOT 2
- How to easily play sound effects with ndsp?
- romfsMountFromTitle error HOT 1
- nfcCmd21 / nfcCmd22 HOT 2
- Memory access out-of-bounds while using std::cout HOT 1
- MEMREGION_APPLICATION : MemRegionUsed and MemRegionSize return the same value, MemRegionFree returns 0 HOT 1
- If homebrew is launched directly after NSMB 2, GPU commands aren't being executed anymore HOT 1
- Where is sockaddr_in6 defined? HOT 4
- Global macros clash with other things
- Socket connections fail to work if DHCP just assigned IP this boot HOT 3
- Latest libctru makes app crash on exit HOT 1
- shaderInstanceInit doesn't initialize numFloat24Uniforms if no constant table is present
- Document alignment requirements for ndspWaveBuf
- DmaConfig's DmaDeviceConfig flags and structure reversed in terms of src/dst
- PTM:CheckNew3DS is wrong
- NDSP apparently over-reads data on short sound effects
- GPU Command Buffer Causes Crash When Filled/Overran HOT 1
- 1. In included file: 'sys/lock.h' file not found [pp_file_not_found] HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libctru.