spinettaro / delphi-event-bus

Delphi Event Bus (for short DEB) is an Event Bus framework for Delphi
Apache License 2.0
466 stars 110 forks source link

infinite loop in TRTTIUtils.Clone #4

Closed edwinyzh closed 4 years ago

edwinyzh commented 8 years ago

Hello Daniele,

So I've just started integrating delphi-event-bus into my program. The first issue I'm experiencing is that, TEventBus.Post will be in a dead-loop in line 162, which calls TRTTIUtils.Clone, which in turn loop infinitely in line 827:

if Field.GetValue(cloned).IsEmpty then
        begin
          targetObject := TRTTIUtils.Clone(sourceObject); // infinite loop here...

I guess it must has something to do with my event definition:

  // Base event about a TWoDoc
  TBaseDocEvent = class(TBaseAppEvent)
  private
    FDoc: TWoDoc;
  public
    property Doc: TWoDoc read FDoc write FDoc;
  end;

Where TWoDoc has properties like

   property ParentDoc: TWoDoc read FDoc write FDoc;
   property NextSibling: TWoDoc read FDoc write FDoc;
   // and so on...

I wish you can shed some light on the issue, thanks.

edwinyzh commented 8 years ago

Update 1: Fixed the issue by replacing TRTTIUtils.Clone with LEvent := ObjectClone.TObjectClone.From(AEvent);

ObjectClone is from delphihaven.wordpress.com

But I'm not sure if that will introduce any other issues...

spinettaro commented 8 years ago

Hi Edwin, The RTTIUtilsU.pas is an external unit from Delphi MVC . Can you write a unit test to reproduce the bug ? So I can verify it on DMVC.

edwinyzh commented 8 years ago

I guess the issue is about circular reference of objects, but I'm not sure. I'm not able to provide a unit test, but if a screen-recording (showing the Delphi IDE's stack tracing ,etc) would help I could make one, and send you privately.

spinettaro commented 8 years ago

Thanks Edwin, but don't worry I'll create the unit test.

spinettaro commented 4 years ago

Removed the internal CloneEvent as the new architecture is interfaced based https://github.com/spinettaro/delphi-event-bus/commit/307a2cfab813b4b56221e40ecdb6e6a3d6cdb3f4