Crash on MacOs
Crash on MacOs
11 Jul 2024, 07:09
Hello Guys, I have a tool, which is working properly on Windows, But when I test it on MacOs. I got this message below? Can you help me about it?
I use combobox inside of it? may it cause the crash?
Application Specific Information:
*** Terminating app due to uncaught exception 'System.InvalidCastException', reason: 'Unable to cast object of type 'System.Collections.Specialized.SingleItemReadOnlyList' to type 'System.Collections.Generic.IList`1[System.String]'. (System.InvalidCastException)
at System.Windows.Controls.ItemsControl.OnItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at cTrader.Mac.Views.Controls.AutomateControls.ControlSetWpfControlFieldsVisitor.Visit(AutomateComboBoxControl automateComboBoxControl)
at cTrader.Automate.Domain.Shared.Controls.AutomateComboBoxControl.Accept(IAutomateControlVisitor visitor)
at cTrader.Mac.Views.Controls.AutomateControls.AlgoControls.AlgoControlWrapper.OnControlUpdated(IAutomateControlBase updatedControl)
at cTrader.Automate.Instances.Controllers.Chart.BigControlsWrapper.ApplyUpdates(List`1 updatedControls)
at cTrader.Automate.Instances.Controllers.Chart.BigControlsWrapper.ApplyChanges(ControlChangesDto changes)
at cTrader.Automate.Instances.Controllers.Control.BigControlController.Handle(ControlsChangeMessage message)
at ObjCRuntime.BlockStaticDispatchClass.TrampolineDispatchBlock(IntPtr block)
'
abort() called
terminating with uncaught exception of type NSException
Replies
riskontradealgo
11 Jul 2024, 11:40
( Updated at: 11 Jul 2024, 14:29 )
RE: Crash on MacOs
PanagiotisCharalampous said:
Hi there,
Please share your tool's code so that we can reproduce.
Best regards,
Panagiotis
This problem happens because of the combobox, when I comment what is in the function, bot does not crash.
private void UpdateComboBox()
{
string[] itemsToRemove = { "ALL", "NO TRADE", "LONG TRADES", "SHORT TRADES" };
foreach (var item in itemsToRemove)
{
posComboBox.RemoveItem(item);
}
foreach (var position in Positions)
{
if (position.SymbolName == Symbol.Name)
{
string itemText = $"{position.Id}";
posComboBox.RemoveItem(itemText);
}
}
_buyCount = 0;
_sellCount = 0;
_posCount = 0;
foreach (var position in Positions)
{
if (position.SymbolName == Symbol.Name)
{
string itemText = $"{position.Id}";
_posCount++;
}
}
if (_posCount == 0)
{
posComboBox.AddItem("NO TRADE");
posComboBox.SelectedItem = "NO TRADE";
}
else
{
posComboBox.AddItem("ALL");
posComboBox.SelectedItem = "ALL";
}
foreach (var position in Positions)
{
if (position.SymbolName == Symbol.Name)
{
if (position.TradeType == TradeType.Buy) _buyCount++; else _sellCount++;
string itemText = $"{position.Id}";
posComboBox.AddItem(itemText);
}
}
if (_buyCount > 0)
{
posComboBox.AddItem("LONG TRADES");
}
if (_sellCount > 0)
{
posComboBox.AddItem("SHORT TRADES");
}
}
@riskontradealgo
PanagiotisCharalampous
11 Jul 2024, 14:48
Hi there,
Please share the complete code so that we can just copy/paste, build and run it, and see the problem.
Best regards,
Panagiotis
@PanagiotisCharalampous
riskontradealgo
11 Jul 2024, 15:20
( Updated at: 12 Jul 2024, 07:19 )
RE: RE: Crash on MacOs
After MacOs 5.0.1 Update, crashing issue is solved.
But I am facing some other problems right now.
As you can see from 2 videos below, same code, on same pair but getting different outcomes when I print results of combobox.SelectedIndex and combobox.SelectedItem
Windows
MacOs
@riskontradealgo
PanagiotisCharalampous
12 Jul 2024, 07:20
RE: RE: RE: Crash on MacOs
riskontradealgo said:
After MacOs 5.0.1 Update, crashing issue is solved.
But I am facing some other problems right now.
As you can see from 2 videos below, same code, on same pair but getting different outcomes when I print results of combobox.SelectedIndex and combobox.SelectedItem
Windows
MacOs
Hi there,
We will not be able to help you if you don't share the information we are asking for.
Best regards,
Panagiotis
@PanagiotisCharalampous
riskontradealgo
12 Jul 2024, 07:39
( Updated at: 12 Jul 2024, 09:53 )
RE: RE: RE: RE: Crash on MacOs
Hey there Panagiotis Charalampous , Code is here.
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class PositionListerBot : Robot
{
private ComboBox posComboBox;
private Button _closeButton;
private int _buyCount;
private int _sellCount;
private int _posCount;
protected override void OnStart()
{
// Create and configure the ComboBox
InitializeComboBox();
// Create and configure the Button
_closeButton = new Button
{
Text = "Close Selected",
Top = 40,
Left = 10,
Width = 200,
Height = 30,
};
_closeButton.Click += OnCloseButtonClick;
var _stackPanel = new StackPanel()
{
Width = 200,
Orientation = Orientation.Vertical,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top
};
_stackPanel.AddChild(posComboBox);
_stackPanel.AddChild(_closeButton);
Chart.AddControl(_stackPanel);
// Subscribe to position events
Positions.Opened += OnPositionOpened;
Positions.Closed += OnPositionClosed;
}
private void OnPositionOpened(PositionOpenedEventArgs obj)
{
string itemText = $"{obj.Position.Id}";
posComboBox.RemoveItem(itemText);
UpdateComboBox();
}
private void OnPositionClosed(PositionClosedEventArgs obj)
{
string itemText = $"{obj.Position.Id}";
posComboBox.RemoveItem(itemText);
UpdateComboBox();
}
private void InitializeComboBox()
{
posComboBox = new ComboBox
{
Top = 10,
Left = 10,
Width = 200,
Height = 20,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
BackgroundColor = Color.Transparent
};
posComboBox.SelectedItemChanged += PosComboBox_SelectedItemChanged;
UpdateComboBox();
}
private void UpdateComboBox()
{
string[] itemsToRemove = { "ALL", "NO TRADE", "LONG TRADES", "SHORT TRADES" };
foreach (var item in itemsToRemove)
{
posComboBox.RemoveItem(item);
}
foreach (var position in Positions)
{
if (position.SymbolName == Symbol.Name)
{
string itemText = $"{position.Id}";
posComboBox.RemoveItem(itemText);
}
}
_buyCount = 0;
_sellCount = 0;
_posCount = 0;
foreach (var position in Positions)
{
if (position.SymbolName == Symbol.Name)
{
string itemText = $"{position.Id}";
_posCount++;
}
}
if (_posCount == 0)
{
posComboBox.AddItem("NO TRADE");
posComboBox.SelectedItem = "NO TRADE";
}
else
{
posComboBox.AddItem("ALL");
posComboBox.SelectedItem = "ALL";
}
foreach (var position in Positions)
{
if (position.SymbolName == Symbol.Name)
{
if (position.TradeType == TradeType.Buy) _buyCount++; else _sellCount++;
string itemText = $"{position.Id}";
posComboBox.AddItem(itemText);
}
}
if (_buyCount > 0)
{
posComboBox.AddItem("LONG TRADES");
}
if (_sellCount > 0)
{
posComboBox.AddItem("SHORT TRADES");
}
}
private void OnCloseButtonClick(ButtonClickEventArgs obj)
{
string selectedItem = posComboBox.SelectedItem;
if(string.IsNullOrWhiteSpace(selectedItem)) return;
if (selectedItem == "ALL")
{
// Close all positions
foreach (var position in Positions)
{
ClosePositionAsync(position);
}
}
else if (selectedItem == "LONG TRADES")
{
// Print("CLOSE LONG TRADES");
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Buy && position.SymbolName == Symbol.Name)
ClosePositionAsync(position);
}
}
else if (selectedItem == "SHORT TRADES")
{
// Print("CLOSE SHORT TRADES");
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Sell && position.SymbolName == Symbol.Name)
ClosePositionAsync(position);
}
}
else if (selectedItem != "NO TRADE" && selectedItem != "SHORT TRADES" && selectedItem != "LONG TRADES" && selectedItem != "ALL")
{
// Extract the position Id from the selected item text
var positionId = selectedItem;
foreach (var position in Positions)
{
if (position.Id.ToString() == positionId)
{
ClosePositionAsync(position);
}
}
Positions.Closed += OnPositionClosed;
}
}
private void PosComboBox_SelectedItemChanged(ComboBoxSelectedItemChangedEventArgs obj)
{
Print("Selected Index : " + posComboBox.SelectedIndex);
Print("Selected Item : " + posComboBox.SelectedItem);
}
protected override void OnStop()
{
// Unsubscribe from position events
Positions.Opened -= OnPositionOpened;
Positions.Closed -= OnPositionClosed;
// Unsubscribe from button click event
_closeButton.Click -= OnCloseButtonClick;
}
}
}
@riskontradealgo
riskontradealgo
12 Jul 2024, 12:54
RE: RE: RE: RE: RE: Crash on MacOs
Have you guys checked?
@riskontradealgo
PanagiotisCharalampous
14 Jul 2024, 06:35
Hi there,
It will be fixed in the next update.
Best regards,
Panagiotis
@PanagiotisCharalampous
oraclemtx
15 Jul 2024, 13:10
( Updated at: 16 Jul 2024, 05:51 )
RE: Crash on MacOs
Hi Panagiotis,
Curious as to when you think the next update will be rolled out?
KR,
Ibby
PanagiotisCharalampous said:
Hi there,
It will be fixed in the next update.
Best regards,
Panagiotis
@oraclemtx
PanagiotisCharalampous
16 Jul 2024, 06:31
RE: RE: Crash on MacOs
oraclemtx said:
Hi Panagiotis,
Curious as to when you think the next update will be rolled out?
KR,
Ibby
PanagiotisCharalampous said:
Hi there,
It will be fixed in the next update.
Best regards,
Panagiotis
We cannot provide an ETA unfortunately
@PanagiotisCharalampous
PanagiotisCharalampous
11 Jul 2024, 08:07
Hi there,
Please share your tool's code so that we can reproduce.
Best regards,
Panagiotis
@PanagiotisCharalampous