I have a problem creating an array using the v8 engine. This is what I got so far:
void function(Isolate* isolate) {
EscapableHandleScope scope(isolate);
Local<Array> array = Array::New(isolate, n);
...
}
But my program crashes every time when it reaches the second line. This is the output I receive:
==== C stack trace ===============================
v8::internal::Scope::set_start_position [0x000002A7A393E69E+10258841]
v8::internal::Scope::set_start_position [0x000002A7A37A1C63+8568670]
v8::internal::Scope::set_start_position [0x000002A7A37A1E02+8569085]
v8::internal::Scope::set_start_position [0x000002A7A3004CBC+585655]
I have already tried to create an integer or another object in this function. There it works perfectly. Any idea what went wrong here?
I find out what went wrong. But I am not 100% sure why. After i put the Array initialization in a Context_Scope, it worked. But why had it worked for an Integer initialization (without the context scope)?
There is not enough information here to be able to tell what happened. Based on the snippet you've pasted, all I can say is that n
is not defined so it shouldn't even compile, but clearly that's not the issue you're talking about.
Please compile your code in debug mode, and then run it in a debugger, so that you can get a proper stack trace. Maybe instead of just crashing, it will run into an assertion ("DCHECK") that might shed some light on what's wrong. (Generally speaking, learning how to use a debugger is pretty much a requirement for working with C++.)
It might also be helpful to compare what you have with the official sample code, e.g. https://chromium.googlesource.com/v8/v8/+/master/samples/hello-world.cc.
If you then still need help: please post your entire code, including how you built it and which V8 version you're using.
Edit after your edit of the question:
Things like a missing ContextScope were why I asked to see your entire code ;-)
Small integers are context independent. (That's an implementation detail that you usually don't care about, because for all interesting things you need a context anyway.)