I bet this is a basic question, still, I can’t seem to understand how this works. :oops:
I created my own newLookAndFeel class. I add it by using the following code:
newLookAndFeel = new NewLookAndFeel();
getLookAndFeel().setDefaultLookAndFeel (newLookAndFeel);
It works without problems, until you add multiple instances of the PlugIn and try to delete one.
How should I proceed with deleting the newLookAndFeel object? If I try on the Editor Destructor, after using getLookAndFeel().setDefaultLookAndFeel (0); - it crashes the other PlugIn Instance. So I’m clearly doing something wrong.
If I never delete newLookAndFeel, everything works, but doesn’t that leave memory leaks?
Jules, thank you so much, I will check all this out.
I need to learn about Singleton, as I have no clue on what that is. :oops: I will google about this, maybe I already do this and even don’t know. :lol:
With the code above, newLookAndFeel gets created only once. And since I inherit from DeletedAtShutdown, it doesn’t leak anymore. But something else is leaking, so I will have to hunt that one down.
Ok, EVERYTHING is good now. Unless my single-instance code is totally bad. :oops: Since this is a Windows only app, for now, this should do the trick for the time…
Jules, thank you so much again, as always!
I plan on revisiting my entire Treeview code to make it public. I also want to add a few more options to it, with more keyboard shortcuts. 8) I just need to clean up the code so people don’t laugh at it… :lol:
Much better to just let the singleton macros handle all this for you. Singletons aren’t always quite as simple as they sound - have a look through my singleton code and you’ll see there are a few edge cases that need to be dealt with, especially if you’re using threads.
newLookAndFeel != 0L
…I often see people write that, and it annoys me - why “0L”? It’s the wrong type - you don’t want to compare a pointer to a long, do you? Sure, the compiler will ignore it, internally casting the long to a pointer, but why bother adding a suffix if it’s not even the right one!?
Ok, I know I’m a bit pedantic, but comparing a pointer to an int looks extremely ugly to me, and I’m a little surprised that compilers don’t warn about it. After all, this would be an error:
long myLong = 0L;
if (myPointer == myLong)
If you really want to put an explicit type there, then “(void*) 0” would make more sense!