Skip to content

Commit

Permalink
Fixed too many camera streams error
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Nov 4, 2023
1 parent 064cd46 commit 8249245
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 31 deletions.
4 changes: 2 additions & 2 deletions lib/services/shuffleboard_nt_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class ShuffleboardNTListener {
onWidgetAdded?.call(currentJsonData[jsonKey]!);

widget?.unSubscribe();
widget?.dispose();
widget?.dispose(deleting: true);
});
}

Expand Down Expand Up @@ -448,7 +448,7 @@ class ShuffleboardNTListener {
child['properties']!.putIfAbsent('period', () => Globals.defaultPeriod);

widget?.unSubscribe();
widget?.dispose();
widget?.dispose(deleting: true);
}

onWidgetAdded?.call(currentJsonData[jsonKey]!);
Expand Down
22 changes: 10 additions & 12 deletions lib/widgets/dashboard_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ class DashboardGrid extends StatelessWidget {
widget.previewRect = widget.draggablePositionRect;
widget.previewVisible = false;
widget.validLocation = true;

widget.dispose();
}

void onWidgetUpdate(DraggableWidgetContainer widget, Rect newRect) {
Expand Down Expand Up @@ -282,7 +284,6 @@ class DashboardGrid extends StatelessWidget {
_widgetContainers.remove(nt4Container);
}
}

refresh();
}

Expand Down Expand Up @@ -447,11 +448,10 @@ class DashboardGrid extends StatelessWidget {
} else if (!isValidLocation(previewLocation)) {
_containerDraggingIn = null;

if (!fromLayout) {
if (widget.child is NT4Widget) {
(widget.child as NT4Widget)
..dispose()
..unSubscribe();
if (widget.child is NT4Widget) {
widget.child?.dispose(deleting: !fromLayout);
if (!fromLayout) {
widget.child?.unSubscribe();
}
}

Expand All @@ -471,9 +471,7 @@ class DashboardGrid extends StatelessWidget {

_containerDraggingIn = null;

if (widget.child is NT4Widget) {
(widget.child as NT4Widget).dispose();
}
widget.child?.dispose();

refresh();
}
Expand Down Expand Up @@ -621,15 +619,15 @@ class DashboardGrid extends StatelessWidget {
}

void removeWidget(DraggableWidgetContainer widget) {
widget.dispose();
widget.dispose(deleting: true);
widget.unSubscribe();
_widgetContainers.remove(widget);
refresh();
}

void clearWidgets() {
for (DraggableWidgetContainer container in _widgetContainers) {
container.dispose();
container.dispose(deleting: true);
container.unSubscribe();
}
_widgetContainers.clear();
Expand All @@ -638,7 +636,7 @@ class DashboardGrid extends StatelessWidget {

void onDestroy() {
for (DraggableWidgetContainer container in _widgetContainers) {
container.dispose();
container.dispose(deleting: true);
container.unSubscribe();
}
_widgetContainers.clear();
Expand Down
8 changes: 4 additions & 4 deletions lib/widgets/draggable_containers/draggable_list_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class DraggableListLayout extends DraggableLayoutContainer {
children.remove(container);

container.unSubscribe();
container.dispose();
container.dispose(deleting: true);

refresh();
});
Expand Down Expand Up @@ -209,11 +209,11 @@ class DraggableListLayout extends DraggableLayoutContainer {
}

@override
void dispose() {
super.dispose();
void dispose({bool deleting = false}) {
super.dispose(deleting: deleting);

for (var child in children) {
child.dispose();
child.dispose(deleting: deleting);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
return;
}

child!.dispose();
child!.dispose(deleting: true);
child!.unSubscribe();
child = newWidget;

refresh();
}

@override
void dispose() {
super.dispose();
void dispose({bool deleting = false}) {
super.dispose(deleting: deleting);

child?.dispose();
child?.dispose(deleting: deleting);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class DraggableWidgetContainer extends StatelessWidget {
displayRect = Rect.fromLTWH(x, y, width, height);
}

void dispose() {}
void dispose({bool deleting = false}) {}

void unSubscribe() {}

Expand Down
10 changes: 6 additions & 4 deletions lib/widgets/nt4_widgets/multi-topic/camera_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,20 @@ class CameraStreamWidget extends StatelessWidget with NT4Widget {
}

@override
void dispose() {
void dispose({bool deleting = false}) {
Future(() async {
await streamWidget?.cancelSubscription();

httpClient.close();
clientOpen = false;

lastDisplayedImage?.evict();
streamWidget?.previousImage?.evict();
if (deleting) {
lastDisplayedImage?.evict();
streamWidget?.previousImage?.evict();
}
});

super.dispose();
super.dispose(deleting: deleting);
}

@override
Expand Down
8 changes: 5 additions & 3 deletions lib/widgets/nt4_widgets/multi-topic/field_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ class FieldWidget extends StatelessWidget with NT4Widget {
}

@override
void dispose() {
super.dispose();
void dispose({bool deleting = false}) {
super.dispose(deleting: deleting);

field?.dispose();
if (deleting) {
field?.dispose();
}
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/nt4_widgets/nt4_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mixin NT4Widget on StatelessWidget {
nt4Topic ??= nt4Connection.getTopicFromName(topic);
}

void dispose() {}
void dispose({bool deleting = false}) {}

void unSubscribe() {
if (subscription != null) {
Expand Down

0 comments on commit 8249245

Please sign in to comment.