You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
InvalidOperationException on Mac: This PlotModel is already in use by some other PlotView control. #139
I have a Xamarin.Forms app that runs well on Android, iOS and UWP. When running on MacOS, however, I get errors when updating the plot (by re-assigning the PlotModel):
System.InvalidOperationException: This PlotModel is already in use by some other PlotView control.
at OxyPlot.PlotModel.OxyPlot.IPlotModel.AttachPlotView (OxyPlot.IPlotView plotView) [0x00011] in <aa89ede85c2344f7894022daa95cfaf3>:0
at OxyPlot.Xamarin.Mac.PlotView.set_Model (OxyPlot.PlotModel value) [0x00027] in <bc79692f004c40a5a09a55685ae301d5>:0
at OxyPlot.Xamarin.Forms.Platform.MacOS.PlotViewRenderer.OnElementChanged (Xamarin.Forms.Platform.MacOS.ElementChangedEventArgs`1[TElement] e) [0x00029] in <8e51f4d8166f43efa82d9a432db15ebc>:0
at Xamarin.Forms.Platform.MacOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x0017a] in <6cf85f52b2ba4368b7f5ac91b0fb6d86>:0
This happens both with 2.0.0-beta.1 and 2.0.0-beta.2
It indicates the same PlotModel is attached to a second PlotView: can only have one PlotModel per view, and if you want to 'change' view, you need to assign the Model of that view to null or some other PlotModel before assigning the Model of the view to which you want to reassign the PlotModel (so that the PlotModel is informed that it is no longer attached to the old view)
It indicates the same PlotModel is attached to a second PlotView
Well, in fact I'm only using a single PlotView. So either this view is somehow destroyed and re-created under certain conditions, or some other weird thing is going on (as mentioned, the same code works fine on all other platforms). I'll need to look into this a bit deeper, I guess ...
In PR #140, I tried to override the PlotView.Dispose method on Mac (and dispose the Model there, as suggested in oxyplot/oxyplot#497 (comment)), but unfortunately that doesn't seem to help (I still get the same InvalidOperationExceptions).
Activity
janusw commentedon Dec 21, 2022
I tried to work around it by only modifying the PlotModel instead of assigning a completely new one, but the error still occurs.
VisualMelon commentedon Dec 21, 2022
It indicates the same
PlotModelis attached to a secondPlotView: can only have onePlotModelper view, and if you want to 'change' view, you need to assign theModelof that view tonullor some otherPlotModelbefore assigning theModelof the view to which you want to reassign thePlotModel(so that thePlotModelis informed that it is no longer attached to the old view)janusw commentedon Dec 21, 2022
Well, in fact I'm only using a single PlotView. So either this view is somehow destroyed and re-created under certain conditions, or some other weird thing is going on (as mentioned, the same code works fine on all other platforms). I'll need to look into this a bit deeper, I guess ...
VisualMelon commentedon Dec 21, 2022
I've seen users having issues with virtualisation in the past; maybe there's a difference there?
janusw commentedon Jan 1, 2023
Hm, not sure what exactly you mean here. I'm not using any kind of virtualization.
janusw commentedon Jan 1, 2023
Btw this issue seems to be somewhat related to oxyplot/oxyplot#497
janusw commentedon Jan 1, 2023
In PR #140, I tried to override the
PlotView.Disposemethod on Mac (and dispose the Model there, as suggested in oxyplot/oxyplot#497 (comment)), but unfortunately that doesn't seem to help (I still get the same InvalidOperationExceptions).