spinettaro/delphi-event-bus

infinite loop in TRTTIUtils.Clone

edwinyzh opened this issue · 5 comments

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.

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...

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.

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.

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

Removed the internal CloneEvent as the new architecture is interfaced based 307a2cf