Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML and V8 - Send custom classes and objects to V8 vm  (Read 2680 times)

0 Members and 1 Guest are viewing this topic.

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
SFML and V8 - Send custom classes and objects to V8 vm
« 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

Thanks.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: SFML and V8 - Send custom classes and objects to V8 vm
« Reply #1 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 ;) ).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: SFML and V8 - Send custom classes and objects to V8 vm
« Reply #2 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.

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: SFML and V8 - Send custom classes and objects to V8 vm
« Reply #3 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
« Last Edit: September 14, 2012, 08:58:08 pm by prchakal »

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: SFML and V8 - Send custom classes and objects to V8 vm
« Reply #4 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: SFML and V8 - Send custom classes and objects to V8 vm
« Reply #5 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/