Giter VIP home page Giter VIP logo

Comments (10)

EugeneUr avatar EugeneUr commented on August 22, 2024 1

I went ahead and reimplemented the ChartMarkerImage on top of NSObject, IInterfaceChartMarker based of the swift code and that seems to have solved the problem. This is a really strange error but not sure how much effort it is worth resolving, thank you for all the help.

from ioscharts.xamarin.

Flash3001 avatar Flash3001 commented on August 22, 2024

Custom ChartMarkerImage crashes just on device

from ioscharts.xamarin.

EugeneUr avatar EugeneUr commented on August 22, 2024

Hi Flash,

I am wondering if you were able to figure out this issue? I implemented BalloonMarker from the iOS API and this is only crashing on the device. Alternatively, would you be able to add BalloonMarker to this binding?

Thanks for all the great work!
Eugene

from ioscharts.xamarin.

Flash3001 avatar Flash3001 commented on August 22, 2024

Hey @EugeneUr, unfortunately I wasn't able to figure it out yet.

All I could find until now is pointing to it being related to some object being collected too early. The error code indicates it. But I'm having some trouble diagnosing it as I didn't figure out a way to find out which runtime is causing it yet (Swift's, Objective-C or Mono).

from ioscharts.xamarin.

EugeneUr avatar EugeneUr commented on August 22, 2024

Hey @Flash3001

Here is a more recent, complete stack trace, in the hopes you would be able to figure this out (which would be very helpful :))

2017-05-25 11:06:26.055 MyApp[9808:4682353] critical: Stacktrace:

2017-05-25 11:06:26.055 MyApp[9808:4682353] critical:   at <unknown> <0xffffffff>
2017-05-25 11:06:26.055 MyApp[9808:4682353] critical:   at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0x00007>
2017-05-25 11:06:26.055 MyApp[9808:4682353] critical:   at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Users/builder/data/lanes/4691/3e5ac5ff/source/xamarin-macios/src/UIKit/UIApplication.cs:79
2017-05-25 11:06:26.056 MyApp[9808:4682353] critical:   at UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Users/builder/data/lanes/4691/3e5ac5ff/source/xamarin-macios/src/UIKit/UIApplication.cs:63
2017-05-25 11:06:26.056 MyApp[9808:4682353] critical:   at MyApp.Application.Main (string[]) [0x00008] in /Users/me/Desktop/Apps/MyApp/MyApp/Main.cs:12
2017-05-25 11:06:26.056 MyApp[9808:4682353] critical:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) [0x0001e] in <14c6fb0feb8846a2942059f2fe60aa4c#D1FEA204-516A-8C65-3C2C-8AE0AB4E65EB>:0
2017-05-25 11:06:26.056 MyApp[9808:4682353] critical: 
Native stacktrace:

2017-05-25 11:06:26.149 MyApp[9808:4682353] critical: 	0   MyApp                            0x0000000100d91da4 mono_handle_native_crash + 260
2017-05-25 11:06:26.149 MyApp[9808:4682353] critical: 	1   MyApp                            0x0000000100d9d858 mono_sigsegv_signal_handler + 316
2017-05-25 11:06:26.150 MyApp[9808:4682353] critical: 	2   libsystem_platform.dylib            0x00000001917ed31c _sigtramp + 52
2017-05-25 11:06:26.150 MyApp[9808:4682353] critical: 	3   Charts                              0x000000010295447c _TTSf4g_s_n___TFC6Charts11MarkerImage4drawfT7contextCSo9CGContext5pointVSC7CGPoint_T_ + 108
2017-05-25 11:06:26.150 MyApp[9808:4682353] critical: 	4   Charts                              0x0000000102953f2c _TToFC6Charts11MarkerImage4drawfT7contextCSo9CGContext5pointVSC7CGPoint_T_ + 64
2017-05-25 11:06:26.150 MyApp[9808:4682353] critical: 	5   Charts                              0x00000001029f080c _TTSf4g_n___TFC6Charts13ChartViewBase11drawMarkersfT7contextCSo9CGContext_T_ + 1788
2017-05-25 11:06:26.150 MyApp[9808:4682353] critical: 	6   Charts                              0x00000001029d5e4c _TTSf4d_n___TFC6Charts20BarLineChartViewBase4drawfVSC6CGRectT_ + 8944
2017-05-25 11:06:26.150 MyApp[9808:4682353] critical: 	7   Charts                              0x00000001029cd62c _TToFC6Charts20BarLineChartViewBase4drawfVSC6CGRectT_ + 28
2017-05-25 11:06:26.150 MyApp[9808:4682353] critical: 	8   UIKit                               0x00000001988e24e4 <redacted> + 408
2017-05-25 11:06:26.151 MyApp[9808:4682353] critical: 	9   QuartzCore                          0x0000000195a4ae38 <redacted> + 260
2017-05-25 11:06:26.151 MyApp[9808:4682353] critical: 	10  QuartzCore                          0x000000019594a300 <redacted> + 2784
2017-05-25 11:06:26.151 MyApp[9808:4682353] critical: 	11  QuartzCore                          0x0000000195a4aa08 <redacted> + 56
2017-05-25 11:06:26.151 MyApp[9808:4682353] critical: 	12  QuartzCore                          0x0000000195a4a6c8 <redacted> + 1556
2017-05-25 11:06:26.151 MyApp[9808:4682353] critical: 	13  QuartzCore                          0x0000000195a3fc20 <redacted> + 228
2017-05-25 11:06:26.151 MyApp[9808:4682353] critical: 	14  QuartzCore                          0x0000000195a3fcb4 <redacted> + 44
2017-05-25 11:06:26.151 MyApp[9808:4682353] critical: 	15  QuartzCore                          0x00000001959bb360 <redacted> + 252
2017-05-25 11:06:26.151 MyApp[9808:4682353] critical: 	16  QuartzCore                          0x00000001959e23c0 <redacted> + 504
2017-05-25 11:06:26.151 MyApp[9808:4682353] critical: 	17  QuartzCore                          0x00000001959e2e8c <redacted> + 120
2017-05-25 11:06:26.152 MyApp[9808:4682353] critical: 	18  CoreFoundation                      0x00000001926dc9a0 <redacted> + 32
2017-05-25 11:06:26.152 MyApp[9808:4682353] critical: 	19  CoreFoundation                      0x00000001926da628 <redacted> + 372
2017-05-25 11:06:26.152 MyApp[9808:4682353] critical: 	20  CoreFoundation                      0x00000001926daa74 <redacted> + 956
2017-05-25 11:06:26.152 MyApp[9808:4682353] critical: 	21  CoreFoundation                      0x000000019260ad94 CFRunLoopRunSpecific + 424
2017-05-25 11:06:26.152 MyApp[9808:4682353] critical: 	22  GraphicsServices                    0x0000000194074074 GSEventRunModal + 100
2017-05-25 11:06:26.152 MyApp[9808:4682353] critical: 	23  UIKit                               0x00000001988c3130 UIApplicationMain + 208
2017-05-25 11:06:26.152 MyApp[9808:4682353] critical: 	24  MyApp                            0x00000001002dc684 wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 340
2017-05-25 11:06:26.152 MyApp[9808:4682353] critical: 	25  MyApp                            0x000000010029a9cc UIKit_UIApplication_Main_string___intptr_intptr + 44
2017-05-25 11:06:26.152 MyApp[9808:4682353] critical: 	26  MyApp                            0x000000010029a98c UIKit_UIApplication_Main_string___string_string + 172
2017-05-25 11:06:26.153 MyApp[9808:4682353] critical: 	27  MyApp                            0x00000001000b4eb0 MyApp_Application_Main_string__ + 160
2017-05-25 11:06:26.153 MyApp[9808:4682353] critical: 	28  MyApp                            0x00000001004aaa64 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 244
2017-05-25 11:06:26.153 MyApp[9808:4682353] critical: 	29  MyApp                            0x0000000100da0980 mono_jit_runtime_invoke + 836
2017-05-25 11:06:26.153 MyApp[9808:4682353] critical: 	30  MyApp                            0x0000000100e197dc do_runtime_invoke + 112
2017-05-25 11:06:26.153 MyApp[9808:4682353] critical: 	31  MyApp                            0x0000000100e1ca00 do_exec_main_checked + 152
2017-05-25 11:06:26.153 MyApp[9808:4682353] critical: 	32  MyApp                            0x0000000100d851dc mono_jit_exec + 268
2017-05-25 11:06:26.153 MyApp[9808:4682353] critical: 	33  MyApp                            0x0000000100ee49c4 xamarin_main + 2148
2017-05-25 11:06:26.153 MyApp[9808:4682353] critical: 	34  MyApp                            0x0000000100d43314 main + 96
2017-05-25 11:06:26.153 MyApp[9808:4682353] critical: 	35  libdyld.dylib                       0x000000019161959c <redacted> + 4
2017-05-25 11:06:26.154 MyApp[9808:4682353] critical: 
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

from ioscharts.xamarin.

Flash3001 avatar Flash3001 commented on August 22, 2024

@EugeneUr I was able to reproduce this problem with a new library/binding with just a single field class in Swift.

The error happens when the Swift code tries to access its field (set or get). It seems like the object has been collected before time. I already spent a coupe of hours on it, but without success, what's bugging me is the fact it only happens when the binding is sub-classed.

from ioscharts.xamarin.

markaw375 avatar markaw375 commented on August 22, 2024

Hey @EugeneU, I'm facing the same problem. Could you please share your working implementation of ChartMarkerImage? The error is really strange...

from ioscharts.xamarin.

EugeneUr avatar EugeneUr commented on August 22, 2024

Hi @markaw375,

Sure thing, hope it helps

public class ChartMarkerImage : NSObject, IInterfaceChartMarker
{
	public CGPoint Offset { get; set; }
	public CGSize Size { get; set; }
	public UIImage Image { get; set; }
	public ChartViewBase ChartView { get; set; }

	public virtual CGPoint OffsetForDrawingAtPoint(CGPoint atPoint)
	{
		CGPoint offset = this.Offset;
		ChartViewBase chart = this.ChartView;
		CGSize size = this.Size;

		if (size.Width == 0.0 && this.Image != null)
		{
			size.Width = this.Image?.Size.Width ?? 0;
		}
		if (size.Height == 0.0 && this.Image != null)
		{
			size.Height = this.Image?.Size.Height ?? 0;
		}

		nfloat width = size.Width;
		nfloat height = size.Height;

		if (atPoint.X + offset.X < 0.0)
		{
			offset.X = -atPoint.X;
		}
		else if (chart != null && atPoint.X + width + offset.X > chart.Bounds.Size.Width)
		{
			offset.X = chart.Bounds.Size.Width - atPoint.X - width;
		}

		if (atPoint.Y + offset.Y < 0.0)
		{
			offset.Y = -atPoint.Y;
		}
		else if (chart != null && atPoint.Y + height + offset.Y > chart.Bounds.Size.Height)
		{
			offset.Y = chart.Bounds.Size.Height - atPoint.Y - height;
		}

		return offset;
	}

	public virtual void RefreshContentWithEntry(ChartDataEntry entry, ChartHighlight highlight)
	{
		// Do nothing here...
	}

	[Export("drawWithContext:point:")]
	public virtual void Draw(CGContext context, CGPoint point)
	{
		CGPoint offset = this.OffsetForDrawingAtPoint(point);
		CGSize size = this.Size;

		if (size.Width == 0.0 && this.Image != null)
		{
			size.Width = this.Image?.Size.Width ?? 0;
		}

		if (size.Height == 0.0 && this.Image != null)
		{
			size.Height = this.Image?.Size.Height ?? 0;
		}

		CGRect rect = new CGRect(point.X + offset.X, point.Y + offset.Y, size.Width, size.Height);

		UIGraphics.PushContext(context);
		this.Image?.Draw(rect);
		UIGraphics.PopContext();
	}
}

and the ballon marker which i modified a bit to help it present better

/// <summary>
/// Ballon marker.
/// Based off https://github.com/danielgindi/Charts/blob/5d54cfd6a846df07b44cb7217403e03760bf0311/ChartsDemo/Classes/Components/BalloonMarker.swift
/// </summary>
public class BalloonMarker : ChartMarkerImage
{
	private CGSize arrowSize;
	private CGSize minSize;

	private UIFont font;
	private UIEdgeInsets insets;
	private UIStringAttributes stringAttributes;
	private NSString label;

	public IInterfaceChartAxisValueFormatter valueFormatter { get; set; }
	public Func<UIColor> getFillColor { get; set; }

	public BalloonMarker()
	{
		this.font = UIFont.SystemFontOfSize(18.0f);
		this.insets = new UIEdgeInsets(8.0f, 8.0f, 20.0f, 8.0f);
		this.minSize = new CGSize(60.0f, 10.0f);
		this.arrowSize = new CGSize(15, 11);

		NSMutableParagraphStyle style = NSParagraphStyle.Default.MutableCopy() as NSMutableParagraphStyle;
		style.Alignment = UITextAlignment.Center;

		this.stringAttributes = new UIStringAttributes();
		this.stringAttributes.ForegroundColor = UIColor.White;
		this.stringAttributes.Font = this.font;
		this.stringAttributes.ParagraphStyle = style;
	}

	public override void RefreshContentWithEntry(ChartDataEntry entry, ChartHighlight highlight)
	{
		if (this.valueFormatter != null)
		{
			this.label = new NSString(valueFormatter.Axis(entry.Y, null));
		}
		else
		{
			this.label = new NSString(((float)entry.Y).ToString());
		}

		CGSize labelSize = this.label.StringSize(this.font);

		CGSize size = new CGSize(labelSize.Width + this.insets.Left + this.insets.Right, labelSize.Height + this.insets.Top + this.insets.Bottom);
		size.Width = (nfloat)Math.Max(size.Width, this.minSize.Width);
		size.Height = (nfloat)Math.Max(size.Height, this.minSize.Height);

		this.Size = size;
	}

	public override void Draw(CGContext context, CGPoint point)
	{
		CGRect rect = new CGRect(0, 0, this.Size.Width, this.Size.Height);
		UIGraphicsImageRenderer renderer = new UIGraphicsImageRenderer(Size);

		if (point.Y - this.Size.Height >= 0.0)
		{
			this.Offset = new CGPoint(-this.Size.Width / 2.0f, -this.Size.Height);
			this.Image = renderer.CreateImage((UIGraphicsImageRendererContext rendererContext) =>
			{
				CGContext newContext = rendererContext.CGContext;
				newContext.SetFillColor(this.getFillColor().CGColor);

				newContext.BeginPath();
				newContext.MoveTo(rect.X, rect.Y);
				newContext.AddLineToPoint(rect.X + rect.Size.Width, rect.Y);
				newContext.AddLineToPoint(rect.X + rect.Size.Width, rect.Y + rect.Size.Height - this.arrowSize.Height);
				newContext.AddLineToPoint(rect.X + (rect.Size.Width + arrowSize.Width) / 2.0f, rect.Y + rect.Size.Height - arrowSize.Height);
				newContext.AddLineToPoint(rect.X + rect.Size.Width / 2.0f, rect.Y + rect.Size.Height);
				newContext.AddLineToPoint(rect.X + (rect.Size.Width - arrowSize.Width) / 2.0f, rect.Y + rect.Size.Height - arrowSize.Height);
				newContext.AddLineToPoint(rect.X, rect.Y + rect.Size.Height - arrowSize.Height);
				newContext.AddLineToPoint(rect.X, rect.Y);
				newContext.FillPath();

				rect.Y += this.insets.Top;
				rect.Height -= this.insets.Top + this.insets.Bottom;

				this.label.DrawString(rect, this.stringAttributes);
			});
		}
		else // draw the x-axis inverse
		{
			this.Offset = new CGPoint(-this.Size.Width / 2.0f, 0);
			this.Image = renderer.CreateImage((UIGraphicsImageRendererContext rendererContext) =>
			{
				CGContext newContext = rendererContext.CGContext;
				newContext.SetFillColor(this.getFillColor().CGColor);

				newContext.BeginPath();
				newContext.MoveTo(rect.X, rect.Y + rect.Size.Height);
				newContext.AddLineToPoint(rect.X + rect.Size.Width, rect.Y + rect.Size.Height);
				newContext.AddLineToPoint(rect.X + rect.Size.Width, rect.Y + this.arrowSize.Height);
				newContext.AddLineToPoint(rect.X + (rect.Size.Width + arrowSize.Width) / 2.0f, rect.Y + arrowSize.Height);
				newContext.AddLineToPoint(rect.X + rect.Size.Width / 2.0f, rect.Y);
				newContext.AddLineToPoint(rect.X + (rect.Size.Width - arrowSize.Width) / 2.0f, rect.Y + arrowSize.Height);
				newContext.AddLineToPoint(rect.X, rect.Y + arrowSize.Height);
				newContext.AddLineToPoint(rect.X, rect.Y + rect.Size.Height);
				newContext.FillPath();

				rect.Y += this.insets.Bottom;
				rect.Height -= this.insets.Top + this.insets.Bottom;

				this.label.DrawString(rect, this.stringAttributes);
			});
		}

		base.Draw(context, point);
	}
}

from ioscharts.xamarin.

markaw375 avatar markaw375 commented on August 22, 2024

@EugeneUr thank you very much. It works!

from ioscharts.xamarin.

Flash3001 avatar Flash3001 commented on August 22, 2024

I will close this issue as it is not possible to subclass from a Swift class using the current binding techniques available. In fact, it is not possible to do it even on Objective-C (https://stackoverflow.com/a/35244676/1698917).

The current solution is to do what proposed on the previous comments.

from ioscharts.xamarin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.