Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » Something wrong with Dispatcher?
Something wrong with Dispatcher? [message #36961] Tue, 31 July 2012 22:42 Go to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
I created a class that includes a Dispatcher obj
class MyClass {
  public:
     MyClass() {}
     ...
     Dispatcher<String> disp;
};
, which I included in my app.
Now I'm getting following fatal error when shutting down app:

Quote:

Assertion failed in c:\upp\bazaar\Dispatcher.h, line 51 dests.IsEmpty()


Line 51 gives me Dispatcher destructor:
virtual ~Dispatcher() { ASSERT(dests.IsEmpty()); }


I assume error is due to dests not cleared before Dispatcher obj destruction. So I included destructor to MyClass, to perform just that:
class MyClass {
  public:
     MyClass() {}
     ~MyClass() { disp.Clear(); }
     ...
     Dispatcher<String> disp; // line 35
};

Next I got the following compiler error:
Quote:


c:\upp\bazaar\dispatcher\Dispatcher.h(60) : error C2228: left of '.Unregister' must have class/struct/union
type is 'Dispatchable<T> '
with
[
T=Upp::String
]
did you intend to use '->' instead?
c:\upp\bazaar\dispatcher\Dispatcher.h(60) : while compiling class template member function 'void Dispatch
er<T>::Clear(void)'
with
[
T=Upp::String
]
c:\myapps\MyApp\MyClass.h(35) : see reference to class template instantiation 'Dispatcher<
T>' being compiled
with
[
T=Upp::String
]


Changing '.' to '->' didnīt work either. Finally, I decided to inherit a workaround from Dispatcher:
template <class T>
class MyDispatcher : public Dispatcher<T>
{
 public:
 MyDispatcher() {}
 ~MyDispatcher() {
    const VectorMap<unsigned,Dispatchable<T>*>& dests=GetDests();
    while(dests.GetCount()>0) dests[0]->UnregisterAll(); // * NOTICE '->' INSTEAD OF '.' IN Dispatcher.h CODE!!??
 }
};

Now, replacing
Quote:

Dispatcher<String> disp
by
Quote:

MyDispatcher<String> disp
compiles perfectly and solves the issue completely.
Anyone else having the same??

Tks.

[Updated on: Tue, 31 July 2012 22:51]

Report message to a moderator

Re: Something wrong with Dispatcher? [message #36962 is a reply to message #36961] Wed, 01 August 2012 01:26 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Dispatcher.h line 60 looks like
void Clear() { while(dests.GetCount()>0) dests[0].Unregister(); }

Shouldn't it be changed to
void Clear() { while(dests.GetCount()>0) dests[0]->UnregisterAll(); }
instead? And what about Dispatcher destructor? Wasn't it supposed to call Clear() before returning?

Tks!
Re: Something wrong with Dispatcher? [message #37154 is a reply to message #36962] Fri, 31 August 2012 10:17 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi kropniczki

been on vacation, sorry...
i'll check that issue and get back to you soon..
Re: Something wrong with Dispatcher? [message #37412 is a reply to message #37154] Mon, 01 October 2012 22:03 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
finally i remembered Dispatcher..
sorry for the delay, hope you've been fine with your fix so far.

here comes the reason.

compiling with MSC i did not instantiate Clear method anywhere.
but you were right. to make sure the Dispatcher is empty, one either needs to Clear it manually, or to destroy the Dispatchables first (they will unlink themselves).

a Dispatchable can be destination to multiple sources, so doing an UnregisterAll in the Dispatcher would break that. one must unregister the current dispatcher only

	void Clear() { while(dests.GetCount()>0) dests[0]->Unregister(*this); }


i'll commit the changes..
Re: Something wrong with Dispatcher? [message #37428 is a reply to message #37412] Wed, 03 October 2012 03:13 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Ok, thank you for your reply. So far I'm doing fine with my fix, but I'll compile your commit later (kinda busy right now) and let you know if something odd comes up during compilation.

Hope you had a good time on vacation Razz
Re: Something wrong with Dispatcher? [message #37431 is a reply to message #37428] Wed, 03 October 2012 21:48 Go to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
great time in canada Smile
Previous Topic: Allegro5 - Allegro game programming library v5.x
Next Topic: Bug in Docking
Goto Forum:
  


Current Time: Thu Mar 28 12:56:44 CET 2024

Total time taken to generate the page: 0.00981 seconds