Problems with sceGuSwapBuffers

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
DirkJanssen
Posts: 9
Joined: Mon Jan 11, 2010 1:31 am

Problems with sceGuSwapBuffers

Post by DirkJanssen »

Hi,

I am busy with this code I am porting and when I tried to make a render function the game crashes. It comes down to the sceGuSwapBuffers function. When it is in the code it crashes the second time it hits it, or well not crashes the screen just stays black, no debugtext is shown afterwards, but it does not return to the xmb or anything. If I remove the sceGuSwapBuffers from code, this scene just keeps on updating and the game continues (although nothing is shown on screen except the debugging output that lets me know we are actually continueing)

now my question is what can be a cause for the sceGuSwapBuffers failing? the render function itself is just an empty on:

Code: Select all

// Start our rendering
    sceGuStart(GU_DIRECT,list);

	// Clear screen
	sceGuClearColor(0xff000000);
	sceGuClearDepth(0);
	sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

	DebugOutputWait("RENDER: PSP clear screen code\n");

	// Set the ambient light (everything should be lit)
	sceGuAmbient(0xffffffff);
    DebugOutputWait("RENDER: start\n");
sceGuFinish();
	sceGuSync(0,0);
	sceDisplayWaitVblankStart();
    //sceGuSwapBuffers();
    DebugOutputWait("RENDER: End\n");
This same code is used by me in 3 other projects, working just great so I am a bit confused.

Any ideas or known issues?

other maybe important data:
- 3.xx firmware game
- happens second time it enters the render function, first times it does not fail
- 100% occurance
- no crash, just a eternal hang afai can see
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

try
pspDebugScreenSetOffset(sceGuSwapBuffers());

sceGuSwapBuffers(); swaps the draw and display buffer.
Did you set them up correctly?

Code: Select all

int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
DirkJanssen
Posts: 9
Joined: Mon Jan 11, 2010 1:31 am

Post by DirkJanssen »

Tried that, didn't change anything unfortunately :(

Have I set up the buffers correctly?, I hope so I am using it succesfully on three other projects as well, though this project is 2d and not 3d as the previous projects. Any pointers on what can go wrong with the setting up of the drawbuffers?

Code: Select all

// Initialize the Graphical Unit System
	sceGuInit();

	// We start by creating a list.
	sceGuStart(GU_DIRECT,list);

	// We create a drawbuffer of the 32 bits format.
	sceGuDrawBuffer(GU_PSM_8888,(void*)0,512);

	// We create a display buffer, 480x272 which is the resolution of the PSP screen.
	sceGuDispBuffer(480,272,(void*)0x88000,512);

	// We also create a depthbuffer.
	sceGuDepthBuffer((void*)0x110000,512);

	// We offset so we render in the middle of the 4096x4096 virtual space, leaving enough room to scissor.
	sceGuOffset(2048 - (480/2),2048 - (272/2));

	// create a viewport centered at 2048,2048 width 480 and height 272
	sceGuViewport(2048,2048,480,272);

	// We set the range of our depth tests.
	sceGuDepthRange(0xc350,0x2710);

	// enable custom scissor
	sceGuScissor(0,0,480,272);
	sceGuEnable(GU_SCISSOR_TEST);

	// We setup the depth buffer test.
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);

	// We setup some additional info on rendering.
	sceGuFrontFace(GU_CW);
	sceGuShadeModel(GU_SMOOTH);
	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuEnable(GU_LIGHTING);
	sceGuEnable(GU_BLEND);

    // Alpha blending
	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);

    // We tell the GU that we are done.
	sceGuFinish();

	// Wait untill the list has finished.
	sceGuSync(0,0);

	// Turn on the display
	sceGuDisplay(GU_TRUE);
any ideas?
DirkJanssen
Posts: 9
Joined: Mon Jan 11, 2010 1:31 am

Post by DirkJanssen »

hmmm it seems to be this functions thats causing it?

Code: Select all

sceGuDispBuffer() 
It seems that when I set the third parameter to 0 it just works fine.

Code: Select all

dispbp  - VRAM pointer to where the display-buffer starts  
It seems odd to me that it worked previously but then I thought about it is also the first 3.xx firmware software I am making. Does anybody knows how this differs from the 1.5 firmware software? so that I can understand why it did not go as it should have?
unsigned int
Posts: 18
Joined: Thu Aug 13, 2009 11:42 pm

Post by unsigned int »

Not sure what the root problem is, but I think that change to sceGuDispBuffer() is merely circumventing it.

What you are doing is basically disabling double buffering as you give the same address to the front buffer and the back buffer (both at 0). Usually you would set one to 0 and the other to 512*272*4 (or 0x88000) as you did initially. This should work regardless of firmware version.
DirkJanssen
Posts: 9
Joined: Mon Jan 11, 2010 1:31 am

Post by DirkJanssen »

hmmmm that does not sound so good, may end up with problems in the future :s maybe better to find the root problem, any ideas what it may be?
jsharrad
Posts: 100
Joined: Thu Oct 20, 2005 3:06 am

Post by jsharrad »

If it's 2d then you shouldn't need the depth buffer.. you're using ortho right ? I don't see you setting the projection matrix anywhere
unsigned int
Posts: 18
Joined: Thu Aug 13, 2009 11:42 pm

Post by unsigned int »

I guess nothing actually gets rendered at the moment if this is the whole drawing function so there shouldn't be any need for further setups.

That being said, it might not be the best idea to clear the screen to black every frame as it makes it impossible to see if the problem lies in missing debug output (with pspDebugScreenPrintf I presume?) or in that the frame doesn't get drawn at all.

Clearing the screen to a different color on every frame would help or just drawing to front and back buffer in different color and then just switching them. Like the following code which just clears one buffer to red, the other to green and then toggles back and forth for about 10 seconds.

Code: Select all

sceGuStart(GU_DIRECT,list); 
sceGuClearColor(0xff0000ff); 
sceGuClear(GU_COLOR_BUFFER_BIT); 
sceGuFinish();
sceGuSync(0,0);

sceGuSwapBuffers();

sceGuStart(GU_DIRECT,list); 
sceGuClearColor(0xff00ff00); 
sceGuClear(GU_COLOR_BUFFER_BIT); 
sceGuFinish();
sceGuSync(0,0);

int i = 0;
while &#40;i < 100&#41;
&#123;
  sceKernelDelayThread&#40;100000&#41;;
  sceDisplayWaitVblankStart&#40;&#41;;
  sceGuSwapBuffers&#40;&#41;;
  i++;
&#125;
victorprosa
Posts: 37
Joined: Wed Jan 14, 2009 5:53 am

Post by victorprosa »

I don't work a lot with graphic stuff, but are you sure that 0x88000 is not being used by another process atm, or a previous process used the address and forgot to clean/memset?

Try creaning this specific adress yoursef and see what happens...
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

what is the dimension of the variable list ? it is use to hold all you gu commands
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Re: Problems with sceGuSwapBuffers

Post by Raphael »

DirkJanssen wrote:Hi,
When it is in the code it crashes the second time it hits it, or well not crashes the screen just stays black, no debugtext is shown afterwards
I guess your DebugOutputWait is just a wrapper for pspdebug print?
In that case your screen stays black, because the gu will overdraw your debug printing. Simple reason: debug print works synchronously, while sceGu commands work asynchronously.
If you want your text to display, only print AFTER your sceGuSync.
but it does not return to the xmb or anything.
That just means that you have a bad (infinite) loop in your code. Inserting single lines of code may cause the kernel to suddenly be able to get out of that infinite loop in the forceful exitgame, but most of the time it won't.
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Post Reply