SFML community forums

Help => General => Topic started by: prchakal on September 14, 2012, 05:14:02 pm

Title: SFML and V8 - Send custom classes and objects to V8 vm
Post by: prchakal on September 14, 2012, 05:14:02 pm
Hi,

I made a project that use V8 integration with SFML, but my problem is with custom class/objects that i want that V8 can see.

I created a class "Character" like the same of others "sf_v8" classes. But my application open and close,and the default error "Segment fault".

I can use my project with sf::Sprite class, it is working perfect. But now i want custom classes.

Can anyone help me?

You can see where i stop here:
https://github.com/prsolucoes/sfml-cmake (https://github.com/prsolucoes/sfml-cmake)

Thanks.
Title: Re: SFML and V8 - Send custom classes and objects to V8 vm
Post by: eXpl0it3r on September 14, 2012, 05:23:21 pm
Make use of your debugger, manual debug checks and the calltrace to find out what goes wrong (that's the not so nice part about programming ;) ).
Title: Re: SFML and V8 - Send custom classes and objects to V8 vm
Post by: prchakal on September 14, 2012, 06:22:39 pm
I like debug - step by step :)

I like know whats happen and have full control.

I will search for it, but if you have a light, i will be grateful :)

I think that it is simple and i forgot something, because i copy a sample class in "sf_v8".

Thanks.
Title: Re: SFML and V8 - Send custom classes and objects to V8 vm
Post by: prchakal on September 14, 2012, 07:45:29 pm
One thing i discover, that the errori got here:

Quote
v8::Handle<v8::Object> Result = Character::POT->NewInstance();

I have commited a working version with custom class commented and working with a simple sprite, while i discover how exchange c++ classes to v8.


---------------

UPDATED:

More specific here:

Quote
Character::POT->NewInstance();

---------------

UPDATED - ANOTHER CLUE:

GDB ERROR FROM COMMAND-LINE

Quote
Starting program: /Users/paulo/Pessoal/workspaces/qt/sfml-cmake/build/sfml-project.app/Contents/MacOS/sfml-project
Reading symbols for shared libraries .++++++++++.............................................................................................. done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x000000010012ec25 in v8::internal::Execution::InstantiateObject ()

--------------------

UPDATED - FULL DETAILED

Now i know where is the problem, but dont know how to solve it :(


Quote
Reading symbols for shared libraries . done

Breakpoint 1, main () at /Users/paulo/Pessoal/workspaces/qt/sfml-cmake/main.cpp:82
82       v8::Handle<v8::Object> Result = JSCharacter::POT->NewInstance();
(gdb) step
v8::Handle<v8::ObjectTemplate>::operator-> (this=0x10051bb88) at v8.h:216
216     inline T* operator->() const { return val_; }
(gdb) step

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x000000010012ec25 in v8::internal::Execution::InstantiateObject ()

It is acessing a NULL value but, why?

If we "print" the property "val_", we have a NULL object:

Quote
(gdb) print val_
$1 = ('v8::ObjectTemplate' *) 0x0
Title: Re: SFML and V8 - Send custom classes and objects to V8 vm
Post by: prchakal on September 14, 2012, 09:14:22 pm
PROBEM SOLVED!!!! URRRULLLLLL!!!!

GDB IS THE BEST!!!!!

I need initialize the null attribute "POT":

Quote
JSCharacter::InitPOT(JSCharacter::POT);
v8::Handle<v8::Object> Result = JSCharacter::POT->NewInstance();

Ty.
Title: Re: SFML and V8 - Send custom classes and objects to V8 vm
Post by: eXpl0it3r on September 14, 2012, 10:03:41 pm
PROBEM SOLVED!!!! URRRULLLLLL!!!!

GDB IS THE BEST!!!!!
Glad you discovered that!
The debugger is one of the most important tools for developers and if used right, many of the questions regarding some errors could get fix by the asking person itself, but granted it needs a bit experience to really make use of it. ;)