16
DotNet / AccessViolationException when changing properties
« on: July 17, 2009, 01:36:44 am »
hi there,
ive got a silly problem.
im writing a textbox right now and ive encountered several errors with String2d.
when i change and read properties like Text several times before drawing (often initiated through events) i get the AccessViolationException.
am i doing something wrong or is this a bug? how can i avoid this?
(the last days i avoided this by changing text just before drawing, but now i need to change it several times as i try to measure the width of the string)
this is the code:
ive got a silly problem.
im writing a textbox right now and ive encountered several errors with String2d.
when i change and read properties like Text several times before drawing (often initiated through events) i get the AccessViolationException.
Code: [Select]
System.AccessViolationException was unhandled
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=sfmlnet-graphics
StackTrace:
at SFML.Graphics.String2D.sfString_GetText(IntPtr This)
at SFML.Graphics.String2D.get_Text()
[...]
am i doing something wrong or is this a bug? how can i avoid this?
(the last days i avoided this by changing text just before drawing, but now i need to change it several times as i try to measure the width of the string)
this is the code:
Code: [Select]
public int Width
{
get
{
string oldText = Text;
if (oldText.Length == 0)
return 0;
float start = drawable.GetCharacterPos(0).X;
Text = oldText + "|";
float end = drawable.GetCharacterPos((uint)oldText.Length).X;
Text = oldText;
return (int)(end - start);
}
}