devkitPro / citro3d

Homebrew PICA200 GPU wrapper library for Nintendo 3DS
zlib License
248 stars 35 forks source link

Crash when switching from non-800px mode to 800px mode? #51

Closed mkst closed 4 years ago

mkst commented 4 years ago

I'm not sure if this is meant to be supported, but if I try to change between 400px mode and 800px mode (i.e. C3D_RenderTargetDelete / C3D_RenderTargetCreate) my console crashes - crash_dump_00000001.dmp.gz

a) is this a supported behaviour b) are there some steps I'm not doing?

I'm doing something along the lines of:

    if (gTarget != NULL) // top left screen
    {
        C3D_RenderTargetDelete(gTarget);
        gTarget = NULL;
    }
    if (gTargetRight != NULL) // top right screen
    {
        C3D_RenderTargetDelete(gTargetRight);
        gTargetRight = NULL;
    }

    /// am I missing some steps??

    bool useAA = gfx_config.useAA;
    bool useWide =  gfx_config.useWide; // e.g. toggling between false to true = crash

    u32 transferFlags =
        GX_TRANSFER_FLIP_VERT(0) |
        GX_TRANSFER_OUT_TILED(0) |
        GX_TRANSFER_RAW_COPY(0) |
        GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) |
        GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8);

    if (useAA && !useWide)
        transferFlags |= GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_XY);
    else if (useAA && useWide)
        transferFlags |= GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_X);
    else
        transferFlags |= GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO);

    int width = useAA || useWide ? 800 : 400;
    int height = useAA ? 480 : 240;

    gTarget  = C3D_RenderTargetCreate(height, width, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
    C3D_RenderTargetSetOutput(gTarget,  GFX_TOP, GFX_LEFT,  transferFlags);

    if (!useWide)
    {
        gTargetRight = C3D_RenderTargetCreate(height, width, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
        C3D_RenderTargetSetOutput(gTargetRight, GFX_TOP, GFX_RIGHT, transferFlags);
        gfxSet3D(true);
    }
    else
    {
        gfxSetWide(true);
    }

The code is from the 3ds sm64 port...

mkst commented 4 years ago

OK, throw in a C3D_Fini(); and that seems to have done it.