Dirk
Attached you'll find a small sample application which mimics the
problematic part of my application.
Best regards,
Marco
>>> Dirk Reiners <[EMAIL PROTECTED]> 18.09.2008 14:13 >>>
Hi Marco,
Marco Spoerl wrote:
> Thanks for your tips. Unfortunately, it doesn't seem to be a
ref-count
> problem with the texture array. Both the texture and the image passed
to
> "render" return with the same ref-count they originally had: 1.
Hm, that's not quite clear to me. Did you try manually subRef-ing the
pointers there instead of calling clear()?
> But I
> have to try some of the other possible leak sources mentioned in the
> wiki. And I could try to write a small app to reproduce the
behaviour,
> if this is of any help for the OpenSG developers?
>
That's always the best way to get a quick response. Reproducing the
problem is most of the time 80% of the effort, so if we can save
ourselves that part we're much more likely to give it a shot.
Yours
Dirk
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the
world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users
#pragma warning( push )
#pragma warning( disable : 4100 4127 4189 4201 4231 4244 4251 4267 4275 4996 )
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGRefPtr.h>
#include <OpenSG/OSGWin32Window.h>
#include <OpenSG/OSGRenderAction.h>
#include <OpenSG/OSGPerspectiveCamera.h>
#include <OpenSG/OSGViewport.h>
#include <OpenSG/OSGPassiveBackground.h>
#include <OpenSG/OSGTransform.h>
#include <OpenSG/OSGGroup.h>
#include <OpenSG/OSGOrthographicCamera.h>
#include <OpenSG/OSGFBOViewport.h>
#include <OpenSG/OSGSolidBackground.h>
#include <OpenSG/OSGImage.h>
#include <OpenSG/OSGTextureChunk.h>
#pragma warning( pop )
//-----------------------------------------------------------------------------
static const int TEX_SIZE = 256;
//-----------------------------------------------------------------------------
OSG::RefPtr<OSG::WIN32WindowPtr> g_pWindow(OSG::NullFC);
OSG::RenderAction* g_pAction = 0;
OSG::RefPtr<OSG::FBOViewportPtr> g_pFboViewport(OSG::NullFC);
//-----------------------------------------------------------------------------
void onCreateMain(HWND hWnd)
{
// init OpenSG
OSG::osgInit(0, 0);
g_pWindow = OSG::WIN32Window::create();
g_pAction = OSG::RenderAction::create();
// set pixel format
const PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
24,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
HDC hDc = GetDC(hWnd);
int pixelFormat = ChoosePixelFormat(hDc, &pfd);
SetPixelFormat(hDc, pixelFormat, &pfd);
// create viewport
OSG::NodePtr pCameraBeacon = OSG::makeCoredNode<OSG::Transform>();
OSG::PerspectiveCameraPtr pPerspectiveCam =
OSG::PerspectiveCamera::create();
OSG::beginEditCP(pPerspectiveCam);
pPerspectiveCam->setBeacon(pCameraBeacon);
pPerspectiveCam->setFov(OSG::deg2rad(90));
pPerspectiveCam->setNear(100);
pPerspectiveCam->setFar(1000);
OSG::endEditCP(pPerspectiveCam);
OSG::PassiveBackgroundPtr pPassiveBackground =
OSG::PassiveBackground::create();
OSG::NodePtr pDummyRoot = OSG::makeCoredNode<OSG::Group>();
OSG::ViewportPtr pViewport = OSG::Viewport::create();
OSG::beginEditCP(pViewport);
pViewport->setCamera(pPerspectiveCam);
pViewport->setBackground(pPassiveBackground);
pViewport->setRoot(pDummyRoot);
pViewport->setSize(0, 0, 1, 1);
OSG::endEditCP(pViewport);
// init OpenSG window
OSG::beginEditCP(g_pWindow);
g_pWindow->addPort(pViewport);
g_pWindow->setHwnd(hWnd);
g_pWindow->init();
g_pWindow->deactivate();
OSG::endEditCP(g_pWindow);
}
//-----------------------------------------------------------------------------
void onCreateFbo()
{
// create nodes
OSG::NodePtr pCameraBeacon = OSG::makeCoredNode<OSG::Transform>();
OSG::NodePtr pGeometryNode = OSG::makeCoredNode<OSG::Group>();
// create root node
OSG::NodePtr pRootNode = OSG::makeCoredNode<OSG::Group>();
OSG::beginEditCP(pRootNode);
pRootNode->addChild(pCameraBeacon);
pRootNode->addChild(pGeometryNode);
OSG::endEditCP(pRootNode);
// create camera
OSG::OrthographicCameraPtr pCamera = OSG::OrthographicCamera::create();
OSG::beginEditCP(pCamera);
pCamera->setBeacon(pCameraBeacon);
pCamera->setNear(-1);
pCamera->setFar(1);
pCamera->setAspect(1);
pCamera->setVerticalSize(TEX_SIZE);
OSG::endEditCP(pCamera);
// create background
OSG::SolidBackgroundPtr pBackground = OSG::SolidBackground::create();
OSG::beginEditCP(pBackground);
pBackground->setColor(OSG::Color3f(1,0,0));
OSG::endEditCP(pBackground);
// create viewport
g_pFboViewport = OSG::FBOViewport::create();
OSG::beginEditCP(g_pFboViewport);
g_pFboViewport->setParent(g_pWindow);
g_pFboViewport->setRoot(pRootNode);
g_pFboViewport->setBackground(pBackground);
g_pFboViewport->setCamera(pCamera);
g_pFboViewport->setSize(0, 0, TEX_SIZE - 1, TEX_SIZE - 1);
g_pFboViewport->setStorageWidth(TEX_SIZE);
g_pFboViewport->setStorageHeight(TEX_SIZE);
g_pFboViewport->setGenCubemaps(false);
g_pFboViewport->setGenDepthmaps(false);
g_pFboViewport->setFboOn(true);
g_pFboViewport->setDirty(true);
OSG::endEditCP(g_pFboViewport);
}
//-----------------------------------------------------------------------------
void onSize(const int width, const int height)
{
if (g_pWindow != OSG::NullFC)
{
g_pWindow->resize(width, height);
}
}
//-----------------------------------------------------------------------------
void onPaint()
{
if (g_pWindow != OSG::NullFC)
{
g_pWindow->render(g_pAction);
}
}
//-----------------------------------------------------------------------------
void grab(OSG::TextureChunkPtr pTexture)
{
if (g_pFboViewport != OSG::NullFC)
{
OSG::ImagePtr pImage = OSG::Image::create();
OSG::beginEditCP(pImage);
pImage->set(OSG::Image::OSG_RGBA_PF, TEX_SIZE,
TEX_SIZE);
OSG::endEditCP(pImage);
OSG::beginEditCP(pTexture, OSG::TextureChunk::ImageFieldMask);
pTexture->setImage(pImage);
OSG::endEditCP(pTexture, OSG::TextureChunk::ImageFieldMask);
g_pAction->setAutoFrustum(false);
g_pAction->setCorrectTwoSidedLighting(false);
g_pAction->setFrustumCulling(false);
g_pAction->setOcclusionCulling(false);
g_pAction->setSmallFeatureCulling(false);
g_pAction->setSortTrans(false);
g_pAction->setStateSorting(false);
g_pAction->setStatistics(false);
g_pAction->setVolumeDrawing(false);
g_pAction->setZWriteTrans(false);
OSG::beginEditCP(g_pFboViewport);
g_pFboViewport->getTextures().push_back(pTexture);
OSG::endEditCP(g_pFboViewport);
g_pFboViewport->render(g_pAction);
OSG::beginEditCP(g_pFboViewport);
g_pFboViewport->getTextures().clear();
OSG::endEditCP(g_pFboViewport);
}
}
//-----------------------------------------------------------------------------
OSG::TextureChunkPtr createTexture()
{
OSG::Real32 maximumAnistropy;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnistropy);
maximumAnistropy = OSG::osgMin(maximumAnistropy, OSG::Real32(8.0));
OSG::TextureChunkPtr pTexture = OSG::TextureChunk::create();
OSG::beginEditCP(pTexture);
pTexture->setAnisotropy(maximumAnistropy);
pTexture->setMinFilter(GL_LINEAR);
pTexture->setMagFilter(GL_LINEAR);
pTexture->setWrapS(GL_CLAMP_TO_EDGE);
pTexture->setWrapT(GL_CLAMP_TO_EDGE);
pTexture->setTarget(GL_TEXTURE_2D);
pTexture->setInternalFormat(GL_RGBA8);
OSG::endEditCP(pTexture);
return pTexture;
}
//-----------------------------------------------------------------------------
void leak()
{
OSG::RefPtr<OSG::TextureChunkPtr> pTexture(OSG::NullFC);
while (true)
{
pTexture = createTexture();
grab(pTexture);
}
}
//-----------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_KEYDOWN:
switch (static_cast<int>(wParam))
{
case VK_ESCAPE:
exit(0);
break;
}
break;
case WM_SIZE:
onSize(LOWORD(lParam), HIWORD(lParam));
break;
case WM_PAINT:
onPaint();
leak();
break;
case WM_CREATE:
onCreateMain(hWnd);
onCreateFbo();
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
//-----------------------------------------------------------------------------
int main()
{
// create Win32 window class
WNDCLASS wndClass;
memset(&wndClass, 0, sizeof(wndClass));
wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.hInstance = GetModuleHandle(NULL);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.lpszClassName = L"FboLeak";
if (!RegisterClass(&wndClass))
{
return EXIT_FAILURE;
}
// create Win32 window
HWND hWnd = CreateWindow(L"FboLeak", L"FboLeak",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
NULL,
NULL,
GetModuleHandle(NULL),
0);
ShowWindow(hWnd, SW_SHOWNORMAL);
SetActiveWindow(hWnd);
// main loop
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
DispatchMessage(&msg);
}
delete g_pAction;
return EXIT_SUCCESS;
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users