Results 1 to 7 of 7

Thread: CL_SoundBuffer_Session default constructor has no impl

  1. #1

    Default CL_SoundBuffer_Session default constructor has no impl

    I ran into a crash which I debugged into the fact that the CL_SoundBuffer_Session default constructor doesn't build an impl. Without an impl, most of the member funcs will crash. Furthermore, afaict there's no way to test a CL_SoundBuffer_Session instance for whether it has its "guts" filled in.

    Now, I can code around this prob pretty easily in my app. Question is, why not make the default constructor usage-safe, or perhaps disallow default construction?

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Good question.

    You can think of all ClanLib objects as handles.

    So for example:

    CL_SoundBuffer_Session session_1;
    CL_SoundBuffer_Session session_2 = build_soundbuffer_session()

    session_1 is not initialised
    session_2 contains the handle to the object (maybe shared).

    Numerious clanlib objects (for example CL_Texture) contains an is_null() to determine if an implementation exists. But not all objects do. Because clanlib developers are lazy

    1) You cannot disallow default construction, as it would break clanlib (because we treat objects as shared handles)

    2) You could make the clanlib class usage-safe, by adding "if (impl.is_null()) throw CL_Exception("Not initialised") everywhere. (Only enabled in the debug build). But this is boring to write And maybe not worth the effort.

    3) Add "is_null()" to all objects, so client code can handle the case.

  3. #3
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    The proper solution is to add both is_null() and add a throw_if_null() guard at the entrance of each function.

    It is missing simply because it was boring to code and considered not that important back in the day. It is clearly a mistake that this was left out, since a thrown exception here is far more preferable than a call stack from a crash deep within ClanLib. If someone contributes a patch that does this checking that would be greatly appreciated.

    I personally disagree with the notion that such a check should only be performed in debug builds. In my opinion there should be an actual real life profile report showing a performance problem with such a check before it is left out from release builds. Even for release builds you want your application to crash early in order to improve the quality of your post mortem debugging reports. Plus you'd much rather have your customer call you with "Your application displayed a message box saying CL_SoundBuffer_Session is null" than him saying "your application crashed".

  4. #4

    Default

    Quote Originally Posted by rombust View Post
    Good question.

    3) Add "is_null()" to all objects, so client code can handle the case.
    This'll do just fine. If I add it to my tree, will it show up in future clanlib releases? If not, I have to be careful about upgrading. (I'll have to be careful anyway, as I already have a highly tweaked clanlib tree.)

    Thanks again.

  5. #5
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    For the changes to become official, you will have to send us a patch so we can apply it on our subversion repository.

  6. #6
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I do not like adding a throw_if_null() guard at the entrance of each function.

    It would create safer code, but I am not convinced that it is required for C++ style applications.

    For something like, CL_Texture's get_width(), I see it as an unnecessary performance penalty. (If drawing 1000's of textures for example)

    imo, the application code (or clanlib internal code) should be (when required):
    Code:
    void myfunction()
    {
      if (texture.is_null() ) throw CL_Exception("Panic");
      do_something_cool(texture.get_width(), texture.get_height())
      texture.set_some_options(...)
      texture.set_other_options(...)
    }

  7. #7
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I have added is_null() and throw_if_null() to all relevent classes.
    (Note, nothing currently calls throw_if_null() at the moment)

Similar Threads

  1. Default Active Solution in ClanLib 0.9
    By rombust in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 02-01-2009, 03:49 AM
  2. preserving default app settings...
    By harrio in forum Novashell Game Creation System
    Replies: 5
    Last Post: 04-04-2008, 02:30 AM
  3. default window size...
    By harrio in forum Novashell Game Creation System
    Replies: 6
    Last Post: 02-18-2008, 05:38 PM
  4. sprite constructor
    By Krux in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 09-21-2007, 06:52 AM
  5. Trouble with CL_SoundBuffer_Session
    By somar in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 06-30-2007, 01:30 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •