rive-app / rive-flutter

Flutter runtime for Rive
https://rive.app
MIT License
1.16k stars 180 forks source link

Failed run-time assertion due to RiveRenderObject.dispose() not calling super.dispose() at the end of the method #335

Closed hugovangalen closed 11 months ago

hugovangalen commented 11 months ago

I am using Rive 0.11.6 and I noticed that RiveRenderObject.dispose() method isn't calling super.dispose() as the last method in the function, but as the first.

This causes the following failure:

I/flutter (22660): The following assertion was thrown while finalizing the widget tree:
I/flutter (22660): 'package:flutter/src/rendering/object.dart': Failed assertion: line 1644 pos 12: '!_debugDisposed':
I/flutter (22660): is not true.
I/flutter (22660): 
I/flutter (22660): When the exception was thrown, this was the stack:
I/flutter (22660): #2      RenderObject.dispose (package:flutter/src/rendering/object.dart:1644:12)
I/flutter (22660): #3      RiveRenderObject.dispose (package:rive/src/rive.dart:106:11)
I/flutter (22660): #4      RenderObjectElement.unmount (package:flutter/src/widgets/framework.dart:6221:20)

The fix for this crash is to put super.dispose() at the end of the method, as per RenderBox documentation, like so:

  @override
  void dispose() {
    _artboard.redraw.removeListener(scheduleRepaint);
    super.dispose();
  }
HayesGordon commented 11 months ago

Hi @hugovangalen, thanks for the report.

Interesting that this hasn't popped up before as an issue. This particular code has been there for a long time.

Do you have a reproducible example that results in this crash? Regardless though we'll make the super.dispose() the last call.

hugovangalen commented 11 months ago

I do not have a small example (yet) that triggers this error. This occured in a larger project and haven't been succesful in isolating it, so I suspect at this time it may have to do something with multiple objects nested in the render tree or something...

Admitted, I can't entirely eliminate user error, but the incorrect order in dispose() just stood out to me.

If I can successfully isolate the issue, I'll add to this ticket.

HayesGordon commented 11 months ago

Thanks @hugovangalen . I'll let you know when this is updated

andrewpmoore commented 11 months ago

Not sure when this started happening, as I've not seen it before, but it started happening for me today also. My project too I can't really isolate it as I've got a collection of Rive animations happening and it's when I'm switching between pages with rive animations running on both that it seems to happen.

HayesGordon commented 11 months ago

Should be fixed in v0.11.9 - if the above was the cause of the problem. Please reopen if you encounter it again after bumping to this version.