Dear Mads,

thank you very much for your answer. Please find the simple example
below (it took me some time to make it that small).
The problem occurs even without the usage of additional threads.
I think it's obviously that my code must have a logical mistake -
because it's that simple.
However, according to all the explanations provided in this mailing
list and provided by the tutorials on the developer side I'm not able
to find the problem...

The example is written for windows and you should be able to test it
using a simple console application.
You will see that the crash occurs during the second context creation
using the one and only static but persistent object template.
As I understand the documentation of persistent objects: they are not
influenced by the handle scope and thus the example should work fine.
If you replace the usage of the static object template by two
independent objects template the example does not crash...

Thanks for you support,
Jan

#include <tchar.h>
#include <cstdlib>
#include <iostream>
#include <cassert>
#include <v8.h>
#include <windows.h>

/**
 * Simple singleton implementation.
 */
class Singleton
{
        public:

                /**
                 * Returns the unique singleton object.
                 */
                static Singleton& get()
                {
                        static Singleton singleton;
                        return singleton;
                }

                /**
                 * Returns the unique object template.
                 */
                v8::Persistent<v8::ObjectTemplate> objectTemplate()
                {
                        if (uniqueObjectTemplate.IsEmpty())
                        {
                                uniqueObjectTemplate =
v8::Persistent<v8::ObjectTemplate>(v8::ObjectTemplate::New());

                                // normally here function templates would be 
added
                                
//uniqueObjectTemplate->Set(String::New("functionName"),
createSpecificFunctionTemplate())
                        }

                        return uniqueObjectTemplate;
                }

        private:

                v8::Persistent<v8::ObjectTemplate> uniqueObjectTemplate;
};

int _tmain(int argc, _TCHAR* argv[])
{
        {
                v8::HandleScope handleScope;

                {
                        v8::Persistent<v8::Context> anyContext = 
v8::Context::New(NULL,
Singleton::get().objectTemplate());

                        // do something with this context

                        anyContext.Dispose();
                }
        }

        {
                v8::HandleScope handleScope;

                {
                        // ** CRASH ->
                        v8::Persistent<v8::Context> anyContext = 
v8::Context::New(NULL,
Singleton::get().objectTemplate());
                        // <-- CRASH **

                        // do something with this context

                        anyContext.Dispose();
                }
        }

        std::cout << "Press a key to exit" << std::endl;
        getchar();

        return 0;
}

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to