Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Just a question about the progress  (Read 13446 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Just a question about the progress
« Reply #15 on: July 08, 2009, 02:36:58 pm »
That's why globals are bad. Nobody can control their order of initialization. You should really not load your template config before entering the main function.
Laurent Gomila - SFML developer

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Just a question about the progress
« Reply #16 on: July 08, 2009, 02:41:06 pm »
I "LOAD" them in the main :P. The structure are just initialised before the main cause they are in a static class.
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Just a question about the progress
« Reply #17 on: July 08, 2009, 02:59:04 pm »
And what about destruction ? Sometimes you cannot allow the destruction at an unknown time. You may say there is always a solution but it need more work to do it well.

Another thing about global : using them show that your architecture is badly design.

Conclusion : forget global.
SFML / OS X developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Just a question about the progress
« Reply #18 on: July 08, 2009, 03:04:17 pm »
You shouldn't rely on the initialization order of static or extern variables in different modules because it is undefined.

Are you sure that nothing is accessed before it has been initialized? Check that with your debugger.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Just a question about the progress
« Reply #19 on: July 08, 2009, 03:36:54 pm »
Quote from: "Nexus"
You shouldn't rely on the initialization order of static or extern variables in different modules because it is undefined.

Are you sure that nothing is accessed before it has been initialized? Check that with your debugger.


100% sure. Juste including the file in my project with NO CALL AT all on this raise the opengl error.

Quote from: "Hiura"
And what about destruction ? Sometimes you cannot allow the destruction at an unknown time. You may say there is always a solution but it need more work to do it well.

Another thing about global : using them show that your architecture is badly design.

Conclusion : forget global.


lolll easy conclusion.. How will you implement a global templating without global variable? Huh? Somethime global are needed or useful. My template manager need to be accessed by all elements to provide them their initial value.
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Just a question about the progress
« Reply #20 on: July 08, 2009, 03:41:56 pm »
Quote
Juste including the file in my project with NO CALL AT all on this raise the opengl error.

Which file??
Laurent Gomila - SFML developer

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Just a question about the progress
« Reply #21 on: July 08, 2009, 03:42:29 pm »
The class (sorry).

The problem is that when the program clause and sfml free texture it raise an error on that font.
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Just a question about the progress
« Reply #22 on: July 08, 2009, 05:37:45 pm »
Quote from: "Daazku"
lolll easy conclusion..
Not at all.

Quote from: "Daazku"
How will you implement a global templating[1] without global variable?
Like this :
Code: [Select]
class Manager { ... };
int main(int, char**) {
  Manager mainmanager(...);
  ModuleOne m1(mainmanager, ...);
  ModuleTwo m2(mainmanager, ...);
...
  ModuleN mn(mainmanager, ...);
...

As you see I dislike singleton.

[1] : what d'you mean exactly ? [ 'cause my dictionary doesn't know this word  :wink: . ]
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Just a question about the progress
« Reply #23 on: July 08, 2009, 05:48:38 pm »
An easy fix for you:

1/ If the crash is happening at global startup, instanciate your singleton on demand rather than at global startup
Code: [Select]
class TemplateManager
{
public:

    static TemplateManager& instance()
    {
        static TemplateManager manager;
        return manager;
    }
};


2/ If the crash is happening at global exit, create a function to free resources so that you can control the moment it is done. In fact you always want to control when your resources are cleaned up, trust me ;)
On big projects with tons of modules handling resources and dependencies everywhere, your (lack of) design would never work.
Laurent Gomila - SFML developer

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Just a question about the progress
« Reply #24 on: July 08, 2009, 05:50:15 pm »
Quote from: "Laurent"
An easy fix for you:

1/ If the crash is happening at global startup, instanciate your singleton on demand rather than at global startup
Code: [Select]
class TemplateManager
{
public:

    static TemplateManager& instance()
    {
        static TemplateManager manager;
        return manager;
    }
};


2/ If the crash is happening at global exit, create a function to free resources so that you can control the moment it is done. In fact you always want to control when your resources are cleaned up, trust me ;)
On big projects with tons of modules handling resources and dependencies everywhere, your (lack of) design would never work.


I will see what i can do with that.

PS: The program dont crash. It just leave an opengl exception at the end.
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Just a question about the progress
« Reply #25 on: July 09, 2009, 01:29:58 am »
The error doesn't occur if we do:

font(sf::Font())

instead of

font(sf::Font::GetDefaultFont())

I don't know why, i don't know if it can help to understand anything.. I'm happy with that.
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Just a question about the progress
« Reply #26 on: July 09, 2009, 02:16:00 am »
Just for informations: I modified a LITTLE bit my desing to make templateManager to be a singleton and manager ressources a little better and now all work fine :). (with or without the GetDefaultFont()).
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.