Quantcast
Channel: ClearScript
Viewing all 2297 articles
Browse latest View live

Commented Issue: Fatal error in heap setup, Allocation failed - process out of memory [44]

0
0
Hi,

While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

```
#
# Fatal error in heap setup
# Allocation failed - process out of memory
#
```

```
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 1000; i++)
{
using (V8ScriptEngine engine = new V8ScriptEngine())
{
Console.WriteLine("Created engine #{0}", i);
engine.Execute("function zz(){}");
var tmp = engine.Evaluate("zz");
}
}
}
}
```


Strangely, the memory usage doesn't seem high when it terminates.

I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

Any help will be greatly appreciated.
Thanks in advance again,
Ron

Comments: Fixed in [ClearScript 5.4](https://clearscript.codeplex.com/releases/view/135637).

Edited Issue: Windows script engines leak host objects exposed via dynamic property assignment [47]

0
0
This issue was reported [here](https://clearscript.codeplex.com/discussions/545913). An initial investigation points at a bug in the Windows script runtime. A workaround may be to force the engine to call back to the host to retrieve the property value.

Commented Issue: Windows script engines leak host objects exposed via dynamic property assignment [47]

0
0
This issue was reported [here](https://clearscript.codeplex.com/discussions/545913). An initial investigation points at a bug in the Windows script runtime. A workaround may be to force the engine to call back to the host to retrieve the property value.
Comments: Fixed in [ClearScript 5.4](https://clearscript.codeplex.com/releases/view/135637).

Edited Issue: Memory leak using delegates [48]

0
0
Hi,

It seems V8 engines are not garbage collected if a script uses a host delegate.

```
public class MyClass
{
}

static void DelegateTest()
{
List<WeakReference> enginesWithObject = new List<WeakReference>();
List<WeakReference> enginesWithDelegate = new List<WeakReference>();

for (int i = 0; i < 50; i++)
{
using (var engine = new V8ScriptEngine())
{
engine.AddHostType("MyClass", typeof(MyClass));
engine.Execute("var myClass = new MyClass();");
enginesWithObject.Add(new WeakReference(engine));
}

using (var engine = new V8ScriptEngine())
{
engine.AddHostType("Action", typeof(Action));
engine.Execute("var action = new Action(function(){});");
enginesWithDelegate.Add(new WeakReference(engine));
}
}

// Force garbage collection
GC.Collect();

int enginesWithObjectCnt = 0, enginesWithDelegateCnt = 0;

foreach (var item in enginesWithObject)
{
if (item.IsAlive)
{
enginesWithObjectCnt++;
}
}

foreach (var item in enginesWithDelegate)
{
if (item.IsAlive)
{
enginesWithDelegateCnt++;
}
}
Console.WriteLine("{0} of {1} engines with objects are alive", enginesWithObjectCnt, enginesWithObject.Count);
Console.WriteLine("{0} of {1} engines with delegates are alive", enginesWithDelegateCnt, enginesWithDelegate.Count);
}

```

Note - I'm using latest ClearScript version from 01 June 14.
After run I get:

0 of 50 engines with objects are alive
50 of 50 engines with delegates are alive


Assuming this issue is fixed, what is more recommended to use for a script callback:
use a dynamic call to a script function (not type safe) or to create a host delegate (requiring an additional host call) and call it from host.

Thanks in advance,
Ron




Commented Issue: Memory leak using delegates [48]

0
0
Hi,

It seems V8 engines are not garbage collected if a script uses a host delegate.

```
public class MyClass
{
}

static void DelegateTest()
{
List<WeakReference> enginesWithObject = new List<WeakReference>();
List<WeakReference> enginesWithDelegate = new List<WeakReference>();

for (int i = 0; i < 50; i++)
{
using (var engine = new V8ScriptEngine())
{
engine.AddHostType("MyClass", typeof(MyClass));
engine.Execute("var myClass = new MyClass();");
enginesWithObject.Add(new WeakReference(engine));
}

using (var engine = new V8ScriptEngine())
{
engine.AddHostType("Action", typeof(Action));
engine.Execute("var action = new Action(function(){});");
enginesWithDelegate.Add(new WeakReference(engine));
}
}

// Force garbage collection
GC.Collect();

int enginesWithObjectCnt = 0, enginesWithDelegateCnt = 0;

foreach (var item in enginesWithObject)
{
if (item.IsAlive)
{
enginesWithObjectCnt++;
}
}

foreach (var item in enginesWithDelegate)
{
if (item.IsAlive)
{
enginesWithDelegateCnt++;
}
}
Console.WriteLine("{0} of {1} engines with objects are alive", enginesWithObjectCnt, enginesWithObject.Count);
Console.WriteLine("{0} of {1} engines with delegates are alive", enginesWithDelegateCnt, enginesWithDelegate.Count);
}

```

Note - I'm using latest ClearScript version from 01 June 14.
After run I get:

0 of 50 engines with objects are alive
50 of 50 engines with delegates are alive


Assuming this issue is fixed, what is more recommended to use for a script callback:
use a dynamic call to a script function (not type safe) or to create a host delegate (requiring an additional host call) and call it from host.

Thanks in advance,
Ron




Comments: Fixed in [ClearScript 5.4](https://clearscript.codeplex.com/releases/view/135637).

Edited Issue: Need better error reporting for V8 assembly loading issues [39]

0
0
ClearScript's V8 assembly loading procedure can fail for many reasons, especially in server contexts. Currently all failures result in the same less-than-helpful exception.

Commented Issue: Need better error reporting for V8 assembly loading issues [39]

0
0
ClearScript's V8 assembly loading procedure can fail for many reasons, especially in server contexts. Currently all failures result in the same less-than-helpful exception.
Comments: Fixed in [ClearScript 5.4](https://clearscript.codeplex.com/releases/view/135637).

Edited Issue: CHECK(V8::ArrayBufferAllocator() != NULL) failed [46]

0
0
By default, v8 doesn't have an array buffer allocator. I was able to fix this with in a pure native console app with by adding one following the example as shown in (look at Shell::Main in d8.cc for an example). I figured I would add the same buffer allocator and rebuild v8-ia32.dll and v8-x64.dll, but have not been able to figure out where to add said entry point.

Commented Issue: CHECK(V8::ArrayBufferAllocator() != NULL) failed [46]

0
0
By default, v8 doesn't have an array buffer allocator. I was able to fix this with in a pure native console app with by adding one following the example as shown in (look at Shell::Main in d8.cc for an example). I figured I would add the same buffer allocator and rebuild v8-ia32.dll and v8-x64.dll, but have not been able to figure out where to add said entry point.
Comments: Fixed in [ClearScript 5.4](https://clearscript.codeplex.com/releases/view/135637).

Edited Issue: Strings with embedded null characters are not marshaled correctly to and from V8 [42]

0
0
If a .NET or V8 string has an embedded null character, ClearScript truncates it during marshaling.

Commented Issue: Strings with embedded null characters are not marshaled correctly to and from V8 [42]

0
0
If a .NET or V8 string has an embedded null character, ClearScript truncates it during marshaling.
Comments: Fixed in [ClearScript 5.4](https://clearscript.codeplex.com/releases/view/135637).

Edited Issue: AccessViolationException while calling Dispose on V8ScriptEngine from a Finalizer [51]

0
0
Hi,
I am getting an AccessViolationException while calling V8ScriptEngine from a finalizer.
I can reproduce the issue with below code:
____________________________________________________________________________________
```
namespace ClearScriptLoadTest
{
public class ClearScriptWrapper
{
private Microsoft.ClearScript.V8.V8ScriptEngine v8Engine;
public ClearScriptWrapper()
{
this.v8Engine = new Microsoft.ClearScript.V8.V8ScriptEngine(Microsoft.ClearScript.V8.V8ScriptEngineFlags.None);
}
~ClearScriptWrapper()
{
Console.WriteLine("Finalizer called");
v8Engine.Dispose();
}
}


class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 1000000; i++)
{
ClearScriptWrapper csObj = new ClearScriptWrapper();
GC.Collect();
}
}
}
}

```

____________________________________________________________________________________

__Exception :__

Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at RefCount.Increment(RefCount* )
at SharedPtr<V8Context>.=(SharedPtr<V8Context>* , SharedPtr<V8Context>* that)

at Microsoft.ClearScript.V8.V8ContextProxyImpl.~V8ContextProxyImpl()
at Microsoft.ClearScript.V8.V8ContextProxyImpl.Dispose(Boolean A_0)
at Microsoft.ClearScript.V8.V8ContextProxyImpl.Dispose()
at Microsoft.ClearScript.V8.V8ScriptEngine.Dispose(Boolean disposing)
at Microsoft.ClearScript.ScriptEngine.Dispose()
at ClearScriptLoadTest.ClearScriptWrapper.Finalize() in c:\Users\xxxxxx\Doc
uments\Visual Studio 2013\Projects\ClearScriptLoadTest\ClearScriptLoadTest\Progr
am.cs:line 18

It works fine when dispose is deterministic .

regards
```
skpandey
```

Commented Issue: AccessViolationException while calling Dispose on V8ScriptEngine from a Finalizer [51]

0
0
Hi,
I am getting an AccessViolationException while calling V8ScriptEngine from a finalizer.
I can reproduce the issue with below code:
____________________________________________________________________________________
```
namespace ClearScriptLoadTest
{
public class ClearScriptWrapper
{
private Microsoft.ClearScript.V8.V8ScriptEngine v8Engine;
public ClearScriptWrapper()
{
this.v8Engine = new Microsoft.ClearScript.V8.V8ScriptEngine(Microsoft.ClearScript.V8.V8ScriptEngineFlags.None);
}
~ClearScriptWrapper()
{
Console.WriteLine("Finalizer called");
v8Engine.Dispose();
}
}


class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 1000000; i++)
{
ClearScriptWrapper csObj = new ClearScriptWrapper();
GC.Collect();
}
}
}
}

```

____________________________________________________________________________________

__Exception :__

Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at RefCount.Increment(RefCount* )
at SharedPtr<V8Context>.=(SharedPtr<V8Context>* , SharedPtr<V8Context>* that)

at Microsoft.ClearScript.V8.V8ContextProxyImpl.~V8ContextProxyImpl()
at Microsoft.ClearScript.V8.V8ContextProxyImpl.Dispose(Boolean A_0)
at Microsoft.ClearScript.V8.V8ContextProxyImpl.Dispose()
at Microsoft.ClearScript.V8.V8ScriptEngine.Dispose(Boolean disposing)
at Microsoft.ClearScript.ScriptEngine.Dispose()
at ClearScriptLoadTest.ClearScriptWrapper.Finalize() in c:\Users\xxxxxx\Doc
uments\Visual Studio 2013\Projects\ClearScriptLoadTest\ClearScriptLoadTest\Progr
am.cs:line 18

It works fine when dispose is deterministic .

regards
```
skpandey
```
Comments: Fixed in [ClearScript 5.4](https://clearscript.codeplex.com/releases/view/135637).

Edited Issue: Problems using WindowsScriptEngineFlags.EnableDebugging [36]

0
0
I have code that executes fine on my machine with Visual Studio installed but have passed the code (compiled) including ClearScript.DLL to someone else who is getting an error when the script runs. I have tracked it down that if I remove the EnableDebugging I do not see the crash. But I need this option to get Column and Line numbers for errors in user scripts.

Is this crash caused by a lack of VS on the other machine? If so how do I work around this? I ONLY have the debug option enabled for line and column numbers (running v5.3.9 - not yet tried v5.3.11 as I cannot reproduce so need my colleague to run with latest DLL!)

Stack Trace Info below
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at Microsoft.ClearScript.Windows.ProcessDebugManagerWrapper32..ctor()
at Microsoft.ClearScript.Windows.ProcessDebugManagerWrapper.Create()
at Microsoft.ClearScript.Windows.WindowsScriptEngine.<>c__DisplayClass2.<.ctor>b__0()
at Microsoft.ClearScript.ScriptEngine.ScriptInvoke[T](Func`1 func)
at Microsoft.ClearScript.Windows.WindowsScriptEngine..ctor(String progID, String name, WindowsScriptEngineFlags flags)
at Microsoft.ClearScript.Windows.VBScriptEngine..ctor(String progID, String name, WindowsScriptEngineFlags flags)
at Microsoft.ClearScript.Windows.VBScriptEngine..ctor(String name, WindowsScriptEngineFlags flags)
MY ENTRY POINT -> at Configurator.ScriptProcessor.EnableAPI(API api)


Commented Issue: Problems using WindowsScriptEngineFlags.EnableDebugging [36]

0
0
I have code that executes fine on my machine with Visual Studio installed but have passed the code (compiled) including ClearScript.DLL to someone else who is getting an error when the script runs. I have tracked it down that if I remove the EnableDebugging I do not see the crash. But I need this option to get Column and Line numbers for errors in user scripts.

Is this crash caused by a lack of VS on the other machine? If so how do I work around this? I ONLY have the debug option enabled for line and column numbers (running v5.3.9 - not yet tried v5.3.11 as I cannot reproduce so need my colleague to run with latest DLL!)

Stack Trace Info below
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at Microsoft.ClearScript.Windows.ProcessDebugManagerWrapper32..ctor()
at Microsoft.ClearScript.Windows.ProcessDebugManagerWrapper.Create()
at Microsoft.ClearScript.Windows.WindowsScriptEngine.<>c__DisplayClass2.<.ctor>b__0()
at Microsoft.ClearScript.ScriptEngine.ScriptInvoke[T](Func`1 func)
at Microsoft.ClearScript.Windows.WindowsScriptEngine..ctor(String progID, String name, WindowsScriptEngineFlags flags)
at Microsoft.ClearScript.Windows.VBScriptEngine..ctor(String progID, String name, WindowsScriptEngineFlags flags)
at Microsoft.ClearScript.Windows.VBScriptEngine..ctor(String name, WindowsScriptEngineFlags flags)
MY ENTRY POINT -> at Configurator.ScriptProcessor.EnableAPI(API api)


Comments: Fixed in [ClearScript 5.4](https://clearscript.codeplex.com/releases/view/135637).

Created Unassigned: Issue concatenating java string and c sharp string [55]

0
0
This is in the basic java engine (not v8)

I have some basic code here (in javascript):
```
var accountstr = host.newVar(CLRString);
if (!downloadInfo.TryGetValue("Account", accountstr.out))
{
accountstr = "No Key found";
}
var output = "_" + accountstr;

return output;
```

This should be returning "_908561", but is instead giving me "_undefined". When I remove the underscore concatenation, I get the proper result.

Is there some sort of trick when concatenating a c sharp string and a javascript string?

Edited Unassigned: Issue concatenating java string and c sharp string [55]

0
0
This is in the basic java engine (not v8)

I have some basic code here (in javascript):
```
var accountstr = host.newVar(CLRString);
if (!downloadInfo.TryGetValue("Account", accountstr.out))
{
accountstr = "No Key found";
}
var output = "_" + accountstr;

return output;
```

This should be returning "_908561", but is instead giving me "_undefined". When I remove the underscore concatenation, I get the proper result.

Is there some sort of trick when concatenating a c sharp string and a javascript string?


EDIT:
I managed to find a solution to my problem. For some reason, I have to call .ToString on my System.String. Very weird I had to do this, but it worked.

Closed Unassigned: Issue concatenating java string and c sharp string [55]

0
0
This is in the basic java engine (not v8)

I have some basic code here (in javascript):
```
var accountstr = host.newVar(CLRString);
if (!downloadInfo.TryGetValue("Account", accountstr.out))
{
accountstr = "No Key found";
}
var output = "_" + accountstr;

return output;
```

This should be returning "_908561", but is instead giving me "_undefined". When I remove the underscore concatenation, I get the proper result.

Is there some sort of trick when concatenating a c sharp string and a javascript string?


EDIT:
I managed to find a solution to my problem. For some reason, I have to call .ToString on my System.String. Very weird I had to do this, but it worked.
Comments: Hello! The short answer is that this is working as intended :) Here's the long answer: JavaScript's `+` operator, when its first operand is a string, attempts to convert the second operand to a string by calling its standard `toString()` method. In this case the second operand is a host object. In JScript, host objects are "special" and don't have standard `toString()` methods. Therefore you must explicitly convert the host object to a string. An easy way to do that is to call the host object's _managed_ `ToString()` method, as you discovered. Another possibility, since the host object is a string variable, is to retrieve its value explicitly: ``` JavaScript var output = "_" + accountstr.value; ``` By the way, your error path discards the string variable and replaces it with a native JavaScript string, which has neither a `ToString()` method nor a `value` property. To make the whole thing work, try this: ``` JavaScript var accountstr = host.newVar(CLRString); if (!downloadInfo.TryGetValue("Account", accountstr.out)) { accountstr.value = "No Key found"; } var output = "_" + accountstr.value; return output; ``` Good luck!

Edited Issue: Issue concatenating java string and c sharp string [55]

0
0
This is in the basic java engine (not v8)

I have some basic code here (in javascript):
```
var accountstr = host.newVar(CLRString);
if (!downloadInfo.TryGetValue("Account", accountstr.out))
{
accountstr = "No Key found";
}
var output = "_" + accountstr;

return output;
```

This should be returning "_908561", but is instead giving me "_undefined". When I remove the underscore concatenation, I get the proper result.

Is there some sort of trick when concatenating a c sharp string and a javascript string?


EDIT:
I managed to find a solution to my problem. For some reason, I have to call .ToString on my System.String. Very weird I had to do this, but it worked.

Edited Issue: Issue concatenating java string and c sharp string [55]

0
0
This is in the basic java engine (not v8)

I have some basic code here (in javascript):
```
var accountstr = host.newVar(CLRString);
if (!downloadInfo.TryGetValue("Account", accountstr.out))
{
accountstr = "No Key found";
}
var output = "_" + accountstr;

return output;
```

This should be returning "_908561", but is instead giving me "_undefined". When I remove the underscore concatenation, I get the proper result.

Is there some sort of trick when concatenating a c sharp string and a javascript string?


EDIT:
I managed to find a solution to my problem. For some reason, I have to call .ToString on my System.String. Very weird I had to do this, but it worked.
Viewing all 2297 articles
Browse latest View live




Latest Images