Irrlicht 1.8. Application not closing and memory leak...
Re: Irrlicht 1.8. Application not closing and memory leak...
This :->
void grab() const { ++ReferenceCounter; ++GlobalCounter; }
won´t compile under ANSI C++, unless the variables are mutable.
void grab() const { ++ReferenceCounter; ++GlobalCounter; }
won´t compile under ANSI C++, unless the variables are mutable.
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: Irrlicht 1.8. Application not closing and memory leak...
Static members don't adhere to the const state, thus it should compile with every compiler on the market.
Re: Irrlicht 1.8. Application not closing and memory leak...
Under VS 2010 with default compiler settings, it fails to compile because GlobalCounter is not type mutable and a function declared const cannot change any other variables, which seems pretty logical
Did anyone else compile it with VS2010 ?
Did anyone else compile it with VS2010 ?
Re: Irrlicht 1.8. Application not closing and memory leak...
theorically should be as you say, but the strange thing is thathybrid wrote:You can skip the whole cpp stuff. The methods don't need to be static, nor defined in a cpp file at all. And the static global member can be initialized in one call as 'static int counter=0'. Moreover, I don't see a reason for the methods at all. Just increment the variable directly, the function calls just add huge overhead. If this does not work for you, you did something wrong IMHO.
getGlobalCount() != GlobalCounter. (I have 1 idea on the possible cause, i did nothing wrong, IMHO),
Performance hurt is OK if that allows to debug the project (and anyway if global counter really hurts the performance it can be removed in release with a DEFINE, we are here to find a memory leak, not to discuss that feature integration, and if you are really going to integrate that in irrlicht that's indifferent to me.). Anyway I did nothing wrong, If you do what I did you'll find that I'm correct (tested on mingw at least, for VS really don't know). My guess is that since compiling a DLL will change the name of GlobalCounter to "_GlobalCounter@" and since Irrlicht (problem of irrlicht not of mine) does not have dllexport/dllimport for every class the linker will not find "GlobalCounter" correctly and leave it undefined (infact I was getting linker errors without moving impl to a Cpp file, I had to initialize GlobalCounter in main.cpp to prevent linking errors in a first version, and then I decided to move impl to a Cpp file, performance was not hurt by that in any way.) Irrlicht is exporting only "createIrrlichtDevice" and so I guess is correct it can't find Static members from a dll since they are not exported. (that's how irrlicht is designed so it is ok).
Anyway that code compile fine under mingw. Is strange that VS don't compile it, c++ should allows to call static methods from const methods, they don't take reference/pointer to any class' related object and so they are not changing its members directly (and that's exactly the reason for wich they don't have Constness qualifier)
In my knowloedge I think mingw will give compile error if I write
"mutable static s32 GlobalCounter;"
but maybe since VS is complaining should allow you to do that.(allowing that should not be correct anyway).
@christianclavet: just because I'm curious do you have a 64bit machine?
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Re: Irrlicht 1.8. Application not closing and memory leak...
I tried "mutable static", but that´s not allowed either under VS 2010 compiler. But as const functions are not meant to change anything, mutables aside, then its logical that they can´t also modify a global variable, which itself can´t be mutable as a global variable can´t be a member of a const class.
Re: Irrlicht 1.8. Application not closing and memory leak...
that's correct behaviour. anyway at least on mingw global counter compiles (only "static") it compiles, and should compile also on visual studio then. reading c++ documentation there should be no problem calling a static method from const method. very strange it does not compile. Any one with other VS versions can say anything?
finally found if that memory leach was a real leach? (the motive for wich this discussion started)
EDIT:
even compiling with strict Ansi c++ on mingw did not give any compiler error or warning ("-ansi" switch)
finally found if that memory leach was a real leach? (the motive for wich this discussion started)
EDIT:
even compiling with strict Ansi c++ on mingw did not give any compiler error or warning ("-ansi" switch)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Re: Irrlicht 1.8. Application not closing and memory leak...
I´ll recompile the code changes as exactly above and post the errors.
The leak I´m getting is related to attaching opengl to an mfc window. 12 MB gets lost when the window is closed, but not the whole app.
The leak I´m getting is related to attaching opengl to an mfc window. 12 MB gets lost when the window is closed, but not the whole app.
Re: Irrlicht 1.8. Application not closing and memory leak...
if I'm not wrong also christian had leaks maybe not the same. Does mfc leaks also with other OpenGL applications? (SFML GL demo for example)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Re: Irrlicht 1.8. Application not closing and memory leak...
I can´t compile the modified sample given earlier, if I use Static for the global variable variable, I get this:
1>CGUIToolBar.obj : error LNK2001: unresolved external symbol "private: static int irr::IReferenceCounted::GlobalRefCounter" (?GlobalRefCounter@IReferenceCounted@irr@@0HA)
VS 2010 compiler does not like a static var in a const function it seems.
If I just remove the "static" from the variable declaration, I get this:
1>d:\code_test\irrlicht-1.7.3\include\IReferenceCounted.h(88): error C3490: 'GlobalRefCounter' cannot be modified because it is being accessed through a const object
So I tried placing the variable in the irr workspace of IReferenceCounted before the class declaration (as a global) but it seems to get inserted multiple times causing errors.
1>CGUIToolBar.obj : error LNK2001: unresolved external symbol "private: static int irr::IReferenceCounted::GlobalRefCounter" (?GlobalRefCounter@IReferenceCounted@irr@@0HA)
VS 2010 compiler does not like a static var in a const function it seems.
If I just remove the "static" from the variable declaration, I get this:
1>d:\code_test\irrlicht-1.7.3\include\IReferenceCounted.h(88): error C3490: 'GlobalRefCounter' cannot be modified because it is being accessed through a const object
So I tried placing the variable in the irr workspace of IReferenceCounted before the class declaration (as a global) but it seems to get inserted multiple times causing errors.
Re: Irrlicht 1.8. Application not closing and memory leak...
I wrote "GlobalCounter" not "GlobalRefCounter", unless you changed the code I posted..
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Re: Irrlicht 1.8. Application not closing and memory leak...
Yes, that was the only change.
No idea about MFC and other OpenGL apps. Not seen anything on the web yet via google "MFC OpenGL memory leaks" that seems relevant.
No idea about MFC and other OpenGL apps. Not seen anything on the web yet via google "MFC OpenGL memory leaks" that seems relevant.
Re: Irrlicht 1.8. Application not closing and memory leak...
well nice thing is that adding IRRLICHT_API should now compile fines, bad thing is that there's a leak count of 5, but it can be a fake leak. I have the feeling that certain constructors are called twice just in few classes. (should not happen in theory)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Re: Irrlicht 1.8. Application not closing and memory leak...
For me with VS 2010 its frustrating, nothing compiles!
Setting the GlobalRefCount as a static in the IReferenceCounted class generates an unresolved external error.
On the web I found this below, saying that a re-declaration of the static was needed externally in "one place" for the class, but makes little difference.
http://stackoverflow.com/questions/3050 ... nal-symbol
I still get these errors:-
1>CD3D8ShaderMaterialRenderer.obj : error LNK2001: unresolved external symbol "int irr::GlobalRefCounter" (?GlobalRefCounter@irr@@3HA)
1>CD3D9ParallaxMapRenderer.obj : error LNK2001: unresolved external symbol "int irr::GlobalRefCounter" (?GlobalRefCounter@irr@@3HA)
1>..\..\bin\Win32-visualstudio\Debug\Irrlicht.dll : fatal error LNK1120: 1 unresolved externals
And this is my code:-
Declararion in Irrlicht.cpp:-
namespace irr
{
s32 IReferenceCounted::GlobalRefCounter = 0;
//! stub for calling createDeviceEx
IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDevice(video::E_DRIVER_TYPE driverType,
const core::dimension2d<u32>& windowSize,
u32 bits, bool fullscreen,
bool stencilbuffer, bool vsync, IEventReceiver* res)
{
Declararion in IReferenceCounted:
//! The reference counter. Mutable to do reference counting on const objects.
mutable s32 ReferenceCounter;
static s32 GlobalRefCounter;
};
Setting the GlobalRefCount as a static in the IReferenceCounted class generates an unresolved external error.
On the web I found this below, saying that a re-declaration of the static was needed externally in "one place" for the class, but makes little difference.
http://stackoverflow.com/questions/3050 ... nal-symbol
I still get these errors:-
1>CD3D8ShaderMaterialRenderer.obj : error LNK2001: unresolved external symbol "int irr::GlobalRefCounter" (?GlobalRefCounter@irr@@3HA)
1>CD3D9ParallaxMapRenderer.obj : error LNK2001: unresolved external symbol "int irr::GlobalRefCounter" (?GlobalRefCounter@irr@@3HA)
1>..\..\bin\Win32-visualstudio\Debug\Irrlicht.dll : fatal error LNK1120: 1 unresolved externals
And this is my code:-
Declararion in Irrlicht.cpp:-
namespace irr
{
s32 IReferenceCounted::GlobalRefCounter = 0;
//! stub for calling createDeviceEx
IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDevice(video::E_DRIVER_TYPE driverType,
const core::dimension2d<u32>& windowSize,
u32 bits, bool fullscreen,
bool stencilbuffer, bool vsync, IEventReceiver* res)
{
Declararion in IReferenceCounted:
//! The reference counter. Mutable to do reference counting on const objects.
mutable s32 ReferenceCounter;
static s32 GlobalRefCounter;
};
Re: Irrlicht 1.8. Application not closing and memory leak...
in IReferenceCounted:
?
Code: Select all
class IRRLICHT_API IReferenceCounted //export from dll when compiling/import when linking with dll
{
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Re: Irrlicht 1.8. Application not closing and memory leak...
Thanks, *phew* that fixed it, all compiling, but the global variable isn´t initialising to zero.
Where should I re-declare the static from IReferenceCounted?
I have it here in Irrlicht.cpp which solves the issue with the not be found at link time, but it doesn´t seem to initialise it to zero.
namespace irr
{
s32 IReferenceCounted::GlobalRefCounter = 0; // Why it is necessary to declare this when its declared in the class I do not understand!!!
//! stub for calling createDeviceEx
IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDevice(video::E_DRIVER_TYPE driverType,
const core::dimension2d<u32>& windowSize,
u32 bits, bool fullscreen,
bool stencilbuffer, bool vsync, IEventReceiver* res)
{
Where should I re-declare the static from IReferenceCounted?
I have it here in Irrlicht.cpp which solves the issue with the not be found at link time, but it doesn´t seem to initialise it to zero.
namespace irr
{
s32 IReferenceCounted::GlobalRefCounter = 0; // Why it is necessary to declare this when its declared in the class I do not understand!!!
//! stub for calling createDeviceEx
IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDevice(video::E_DRIVER_TYPE driverType,
const core::dimension2d<u32>& windowSize,
u32 bits, bool fullscreen,
bool stencilbuffer, bool vsync, IEventReceiver* res)
{