Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   Winamp Technical Support (http://forums.winamp.com/forumdisplay.php?f=11)
-   -   Full screen leaks/graphics trouble (http://forums.winamp.com/showthread.php?t=75758)

saragx 14th February 2002 06:57

Full screen leaks/graphics trouble
 
First I'd like to thank the people who have helped me so far with my first plugin. I only take the time to post when I run into a real snag, and I've landed myself in another one.

When run in windowed mode I have no (obvious) memory leaks or de-init problems. In windowed mode I've opened and closed it 30 or so times with no loss of system resources. When run in full screen mode I lose about 1% system resources every other time I start the plugin.

If I start winamp and begin the plugin in full screen mode everything runs and looks fine on the first attempt. If I close the plugin and start it again in full screen, my textures start flashing and become extremely jagged. To fix the problem I have to close out winamp and restart it.

I *think* I have error handling code covering every possible failure on de-init (and init for that matter), but it seems to go through clean on exit every time.

I'm nothing but a pure beginner here, and as such prone to errors I'm sure. If any of you coders out there could check my init and de-init code at the following link I would be more than grateful:

http://www.rit.edu/~jlh1825/vis/visinit.txt

Again, to some of you my problem may be glaringly obvious but I just can't seem to track it down.

Later, and thanks again for your time

--Jon

djsoftwareskins 14th February 2002 17:22

OK
 
The link above seems to b broken (for me)
I can't help u whithout tech details..
How much RAM do u have ?
What OS do u have?
What Graphic card do u have ?

:winamp: :up: :)

saragx 15th February 2002 03:21

Hrm, I'm suprised the link didnt work for you. I will just post the code here in that event. First I'd like to answer your questions though. I'm running WinME (ugh)on a p4 1.5ghz with 128MB ram and a geforce2 64mb video card.

Heres the Init and de-init code which i would recommend pasting into ultraedit or something comparable:

//**********BEGIN

int init(struct winampVisModule *this_mod)
{
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style

RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)WIDTH; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)HEIGHT;

int nPixelFormat;
PIXELFORMATDESCRIPTOR pfd;



//Equivalent of winMain
{ // Register our window class
WNDCLASS wc;
memset(&wc,0,sizeof(wc));
wc.lpfnWndProc = WndProc; // our window procedure
wc.hInstance = this_mod->hDllInstance; // hInstance of DLL
wc.lpszClassName = szAppName; // our window class name
wc.hbrBackground = NULL; // doesn't need a background
wc.style = CS_OWNDC; // added, as window has it's own device context!

if (!RegisterClass(&wc))
{
MessageBox(this_mod->hwndParent,"Error registering window class","Cannot Register Window Class",MB_OK);
return 1;
}
}

if (fullscreenflag) // Attempt Fullscreen Mode?
{
DEVMODE dmScreenSettings; // Device Mode
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = WIDTH; // Selected Screen Width
dmScreenSettings.dmPelsHeight = HEIGHT; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = 16; // Selected Bits Per Pixel
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;


if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{


MessageBox(NULL,"Error","Fullscreen Mode Not Supported By Video Card",MB_OK);
return FALSE; // Exit And Return FALSE
}

}


if (fullscreenflag) // Are We Still In Fullscreen Mode?
{
dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
dwStyle=WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide Mouse Pointer
}
else
{

dwExStyle=WS_EX_APPWINDOW; //| WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
}

AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);

hMainWnd = CreateWindowEx(
dwExStyle, // this exstyle puts a button in the taskbar
szAppName, // our window class name.
this_mod->description, // use description for a window title
WS_VISIBLE|

WS_CLIPSIBLINGS|WS_CLIPCHILDREN | dwStyle, // for OpenGL rendering
0,0, // screen position
WIDTH,HEIGHT, // width & height of window (need to adjust client area later)
this_mod->hwndParent, // parent window (winamp main window)
NULL, // no menu
this_mod->hDllInstance, // hInstance of DLL
0); // no window creation data


if (!hMainWnd)
{
MessageBox(this_mod->hwndParent,"Error creating window","Can't Create Window",MB_OK);
return 1;
//If window not created, quit
}


SetWindowLong(hMainWnd,GWL_USERDATA,(LONG)this_mod); // set our user data to a "this" pointer

{ // adjust size of window to make the client area exactly width x height
RECT r;
GetClientRect(hMainWnd,&r);
SetWindowPos(hMainWnd,
0,
0,
0,
WIDTH*2-r.right,
HEIGHT*2-r.bottom,SWP_NOMOVE|SWP_NOZORDER);
}

//PIXELFORMATDESCRIPTOR described p85-86 OpenGL Superbible
//nPixelFormat declared at top of init function

//function in listing 4-1, modified to avoid being a function
memset(&pfd, 0, sizeof(pfd)); //Size of this structure
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.dwFlags = PFD_SUPPORT_OPENGL | // Support OpenGL calls in window
PFD_DRAW_TO_WINDOW | // Draw to Window (not to bitmap)
PFD_DOUBLEBUFFER; // Double buffered mode
pfd.iPixelType = PFD_TYPE_RGBA, //RGBA mode
pfd.cColorBits = 24, //24 bit colour
pfd.cDepthBits = 16, //Size of depth buffer (changed from 32)
pfd.cStencilBits = 1,
pfd.iLayerType = PFD_MAIN_PLANE, //Draw in main plane

memDC= GetDC(hMainWnd);
//Choose a pixel format that best matches that described in pfd
nPixelFormat = ChoosePixelFormat(memDC, &pfd);

//Set the pixel format for the device context
SetPixelFormat(memDC, nPixelFormat, &pfd);

DescribePixelFormat(memDC, nPixelFormat, sizeof(pfd), &pfd);
hglRC = wglCreateContext(memDC);
wglMakeCurrent(memDC, hglRC);

resize(WIDTH, HEIGHT);
initGL();
ReleaseDC(hMainWnd, memDC);

// show the window
ShowWindow(hMainWnd,SW_SHOWNORMAL);
SetForegroundWindow(hMainWnd); // Slightly Higher Priority
SetFocus(hMainWnd);
startSuccess=true;





//***********INIT OUR OWN SYSTEMS


//get plugin directory




initBalls();
mySphere=gluNewQuadric();
myCylinder=gluNewQuadric();
gluQuadricTexture( mySphere, TRUE);
gluQuadricTexture( myCylinder, TRUE);
mySpecs = V_new();
initCams(0,0);
initCams(liveEffect,0);

TimerInit();
secsPast=1;


LoadGLTextures(0,"c:\\program files\\winamp\\plugins\\Particle.bmp");
LoadGLTextures(1,"c:\\program files\\winamp\\plugins\\boxtex.bmp");
LoadGLTextures(2,"c:\\program files\\winamp\\plugins\\8ball.bmp");
LoadGLTextures(3,"c:\\program files\\winamp\\plugins\\alien.bmp");
LoadGLTextures(4,"c:\\program files\\winamp\\plugins\\stripes.bmp");
LoadGLTextures(5,"c:\\program files\\winamp\\plugins\\bioh.bmp");
LoadGLTextures(6,"c:\\program files\\winamp\\plugins\\shiny.bmp");


return 0;
}//End init function






void quit(struct winampVisModule *this_mod)
{
KillFont();

if (fullscreenflag) // Are We In Fullscreen Mode?
{

ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop
ShowCursor(TRUE); // Show Mouse Pointer
}


if (hglRC) // Do We Have A Rendering Context?
{
if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts?
{
MessageBox(NULL,"Release Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}


if (!wglDeleteContext(hglRC)) // Are We Able To Delete The RC?
{
MessageBox(NULL,"Release RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}

hglRC=NULL; // Set RC To NULL
}


if (memDC && !ReleaseDC(hMainWnd,memDC)) // Are We Able To Release The DC
{
MessageBox(NULL,"Release DC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
memDC=NULL; // Set DC To NULL
}

if (hMainWnd && !DestroyWindow(hMainWnd)) // Are We Able To Destroy The Window?
{
MessageBox(NULL,"Could Not Release hMainWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hMainWnd=NULL; // Set hMainWnd To NULL
}

if (!UnregisterClass(szAppName,this_mod->hDllInstance)) // Are We Able To Unregister Class
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
// Set hInstance To NULL
}




}


LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SIZE:
{
int x, y;
x=LOWORD(lParam);
y=HIWORD(lParam);

memDC= GetDC(hMainWnd);
wglMakeCurrent (memDC, hglRC);

resize(x,y); //call resize function
WIDTH=x; //set WIDTH and HEIGHT to new values
HEIGHT=y;
PostMessage(hwnd, WM_PAINT, 0, 0);
}
return 0;
case WM_CREATE:


return 0;
case WM_ERASEBKGND: return 0;
case WM_PAINT:
{ // update from doublebuffer
default:
PAINTSTRUCT ps;


BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
break;
}
return 0;
case WM_DESTROY:
//Tell the application to terminate after the window is gone
PostQuitMessage(0); return 0;
case WM_CHAR:
{

debugVar=(float)wParam;
switch (wParam){
case 'q':
PostQuitMessage(0);//end program
break;
case 'd':
debugMode=!debugMode;
break;
case 'n':
liveEffect++;
camera[liveEffect].camMovX=0.0f;
camera[liveEffect].camMovY=0.0f;
camera[liveEffect].camMovZ=0.0f;
if(liveEffect == (NUM_EFFECTS + 1)){
liveEffect=1;
}
initCams(liveEffect,0);
break;
case 'i':
camera[liveEffect].camMovZ-=0.3f;
break;
case 'j':
camera[liveEffect].camMovX-=0.3f;
break;
case 'k':
camera[liveEffect].camMovZ+=0.3f;
break;
case 'l':
camera[liveEffect].camMovX+=0.3f;
break;
case 'u':
camera[liveEffect].camMovY+=0.3f;
break;
case 'o':
camera[liveEffect].camMovY-=0.3f;
break;
case 'r':

initCams(liveEffect,0);
break;
case 't':
bHeight+=.1f;
break;
case 'y':
bHeight-=.1f;
break;




}


}
return 0;
case WM_KEYDOWN:
{
winampVisModule *this_mod = (winampVisModule *) GetWindowLong(hwnd,GWL_USERDATA);
//PostMessage(this_mod->hwndParent,message,wParam,lParam);
}
return 0;
case WM_KEYUP:
{
camera[liveEffect].camMovX=0.0f;
camera[liveEffect].camMovY=0.0f;
camera[liveEffect].camMovZ=0.0f;
winampVisModule *this_mod = (winampVisModule *) GetWindowLong(hwnd,GWL_USERDATA);
PostMessage(this_mod->hwndParent,message,wParam,lParam);
}
return 0;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case 6:
break;
default:
break;
}
}
return 0;
case WM_MOVE:
{ // get config_x and config_y for configuration
if (startSuccess){
RECT r;
GetWindowRect(hMainWnd,&r);

}
}
return 0;

}
return DefWindowProc(hwnd,message,wParam,lParam);
}
//******END

Thanks!

Jon

djsoftwareskins 15th February 2002 11:26

Hmm..
 
I'm surprised that u have OpenGL trouble on GeForce2. I have GF 3, and no probs. so far...
do u have the latest drivers ?
if no, update them here
Try re-installing the drivers u have if ya don't wawnna download the new ones...

:winamp:

saragx 15th February 2002 17:33

I am in fact using the latest drivers for the card...I'm pretty sure my poor coding is the source of the error. When using NeHe's initialization code, snippets of which I have put into my own plugin, I have absolutely no trouble with the fullscreen. Only when running this code do I see the problems.

djsoftwareskins 15th February 2002 17:48

Sorry for the bad link thing.. but my ISP had some tech. difficulties...(now it's done) If u have the latest drivers , uninstall & reinsatll it again.
As I have little prog. knoledge, I can't see anithing wrong..
I remember u said taht it works for some time and then it stops. Maybe the drivers are causing it. How does your Sys work in games ? (that use OpenGl!) ?
:winamp:


All times are GMT. The time now is 08:50.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.