[solved]WindowId: shouldn't it be a pointer type?

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
not_a_commie
Posts: 19
Joined: Wed Mar 21, 2007 6:22 pm

[solved]WindowId: shouldn't it be a pointer type?

Post by not_a_commie »

I always get nervous when I see code like this in the .NET wrappers:

windowHandle.ToInt32() // in the CP wrapper

p.WindowId = reinterpret_cast<irr::s32>((void*)windowHandle); // packaged

WindowId should probably be declared as a void*. That way it will always be the correct size. It's used as an HWND, which is definitely a pointer type on Windows. I'm not sure what it is on other operating systems, but I'm sure they could handle a larger data type as well.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Other OS do not have HWND.
not_a_commie
Posts: 19
Joined: Wed Mar 21, 2007 6:22 pm

Post by not_a_commie »

hybrid wrote:Other OS do not have HWND.
That's fine, but other OS's have some kind of window/file handle. And I bet that on a 64bit OS, those handles are 64bits. Regardless, a 32bit HWND is too small on a Win64 platform.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Linux now has an unsigned long id and a void pointer since 1.3
techiemac
Posts: 14
Joined: Tue Dec 26, 2006 7:16 pm

Post by techiemac »

What about the possiblity of using a template.

One way I have gotten around OS specific things is to create a lightweight template object and then typedef the whole thing. Other methods can then be added to the template to help with specific requirements of the irrlicht engine.

For example

Code: Select all


template <typename T>
class MyOsGenericClass
{

  public:
  
  /// Constructor.
  /// \param obj  OS specific object
  MyOsGenericClass(T obj);

  /// Retrieves the object.
  /// \return OS specific object
  T GetOsGenericObj();

  private:

  /// Object
  T m_obj;
};

#if defined _WIN32

/// Windows specific concept
typedef MyOsGenericClass<HWND> OsSpecificWindow;

#elif defined OTHER_OS

/// Whatever os specific concept goes here
typedef MyOsGenericClass<uint64_t> OsSpecificWindow;

#endif

Then your object uses OsSpecificWindow as it's object type.

Just a thought instead of using raw pointers :)
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

template's a waste, at least for this WindowId thing. HWND is just a pointer anyways.
Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

It should just be a dumb void*. Using the template here does nothing other than hide the pointer behind a template.

Travis
techiemac
Posts: 14
Joined: Tue Dec 26, 2006 7:16 pm

Post by techiemac »

I was just throwing it out there. It would at least hide the pointer specific cast from the user. But if you all feel that it's a waste, I'll retract my comment :)

On a side note, one advantage of hiding pointers behind templates is you can move to more of a smart pointer paradigm (see boost::smart_ptr... think reference counting auto_ptr for those that are not familiar). Things such as auto deletion (which Irrlicht already does do somewhat as part of any object derived from IUnknown), throw exception on NULL dereference for more customized exception handling, etc.

But again, I retract my comment if there is no use for them to solve this particular problem.
not_a_commie
Posts: 19
Joined: Wed Mar 21, 2007 6:22 pm

Post by not_a_commie »

I notice in the latest code that WindowId was changed to void*. That's good. There's a bug in one of the examples where the line:

param.WindowId = reinterpret_cast<s32>(hIrrlichtWindow); // hColorButton

should be

param.WindowId = hIrrlichtWindow; // hColorButton
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

That's also fixed already :wink: Simply update again.
Post Reply