Errors while putting key-value pair into Hashtable

InnerVoice
edited October 2014 in Native
Hello!

I'm using Marmalade and Visual C++ 2010 Express with my project. I'm facing the following problem in the code:

[code2=cpp]...
#include "LoadBalancingClient.h"


bool StartScene::init()
{
using namespace ExitGames::Common;
Hashtable ev;
// nByte key and int value:
const nByte POS_X = 101;
int x = 10;
ev.put(KeyObject<nByte>(POS_X), ValueObject<int>(x));
.....
}[/code2]

This is the code I've copypasted to my project from Photon Cloud API reference I found here (http://proglabs.googlecode.com/hg-histo ... erence.pdf) at the article 3.1.3.10 Hashtable::put

But when I build this code, a bunch of errors occur:

Error 23 error C2079: "ExitGames::Common::Helpers::ConfirmAllowedKey<CType>::ASSERTION_FAILED_ERROR_UNSUPPORTED_KEY_TYPE" uses undefined struct "ExitGames::Common::Helpers::CompileTimeAssertTrue<__formal>" c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\helpers\confirmallowedkey.h 24

Error 24 error C2039: type: is not a member "ExitGames::Common::Helpers::ConfirmAllowedKey<CType>" c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\hashtable.h 103

Error 25 error C2065: type: undeclared identifier c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\hashtable.h 103

Error 26 error C2146: syntax error: missing ";" before identifier "forceCompilationToFailForUnsupportedKeyTypes" c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\hashtable.h 103

Error 27 error C2065: forceCompilationToFailForUnsupportedKeyTypes: undeclared indentifier c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\hashtable.h 103

Error 28 error C2065: forceCompilationToFailForUnsupportedKeyTypes: undeclared identifier c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\hashtable.h 103

Error 29 error C2039: TypeCode: is not a member "ExitGames::Common::ValueObject<Etype>" c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\helpers\confirmallowed.h 27

Error 30 error C2882: TypeCode: illegal use of namespace identifier in expression c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\helpers\confirmallowed.h 27

Error 31 error C3203: CustomType: unspecialized class template can't be used as a template argument for template parameter "Base", expected a real type c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\helpers\confirmallowed.h 27

Error 32 error C2955: ExitGames::Common::CustomType: use of class template requires template argument list c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\helpers\confirmallowed.h 27

Error 33 error C2955: ExitGames::Common::Helpers::IsDerivedFrom: use of class template requires template argument list c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\helpers\confirmallowed.h 27

Error 34 error C2079: "ExitGames::Common::Helpers::ConfirmAllowed<CType>::ASSERTION_FAILED_ERROR_UNSUPPORTED_VALUE_TYPE" uses undefined struct "ExitGames::Common::Helpers::CompileTimeAssertTrue<Is>" c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\helpers\confirmallowed.h 27

Error 35 error C2039: TypeCode: is not a member "ExitGames::Common::ValueObject<Etype>" c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\helpers\confirmallowed.h 32

Error 36 error C2882: TypeCode: illegal use of namespace identifier in expression c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\helpers\confirmallowed.h 32

Error 37 error C2866: ExitGames::Common::Helpers::ConfirmAllowed<CType>::customTypeName: a const static data member of a managed type must be initialized at the point of declaration c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\helpers\confirmallowed.h 32

Error 38 error C2512: ExitGames::Common::ValueObject<Etype>: no appropriate default constructor available c:\marmalade projects\stickrun_repo\framework\photon\common-cpp\inc\hashtable.h 104

What could possibly be wrong? Thank you for your answers.

Comments

  • Hi.

    Well, you are referring to a version of the API reference, which (judging from the copyright info) is from some time in 2011 and which seems to even be back from the time before we have even supported Marmalade as a Client platform (otherwise it would be listed as platform that is targeted by the doc on page 1 of the doc).

    Since then there have been quite a few changes and that old doc doesn't match the current client SDK anymore.

    From the errors you are getting, I guess, that you are using client version of 3.0.4.0 or higher.

    In that case your put() call should look like this:
    [code2=cpp]ev.put(POS_X, x);[/code2]

    Please always use the version of the API reference, that is included in the SDK, that you are using, so that you can be sure that its up to date and matching the client version that you are using.

    For questions about how to send and receive certain data types you can also always have a look at the demo_advanced demo inside the SDK which gives example code for all kind of data, even for stuff like object arrays, multidimensional arrays, nested Dictionaries or custom types.
  • Kaiserludi, thank you for fast your response!

    Putting values into hashtable is working fine now, but I haven't found the demo_advanced demo in SDK for Marmalade (it only contains LoadBalancing demo, which contains no information about sending data through hashtables). So I faced problems in getting values from hashtable:

    [code2=cpp]Hashtable ev;
    // nByte key and int value:
    const nByte POS_X = 101;
    int x = 10;
    ev.put((POS_X), (x));

    int *value = (int*) ev.getValue(POS_X);
    int y = *value;[/code2]

    API Reference says that getValue() returns the pointer to a value in the Hashtable. The monitor of "y" says it has value of 1441784644, but it supposed to be 10.
  • Ah, you are using the cloud SDK, right. That one only contains demos that can run on the cloud. We have not found time yet to make a cloud-version of demo_advanced, however when it comes to type support there is no difference between Lite, which is targeted by that demo, and LoadBalancing, which is running on the cloud. I have attached the two interesting source files of demo_advanced to this post. They are copied from the 3.2.1.1 Photon Server C++ Client SDKs code.
    The two functions of interest are sendData() and onEvent().

    For your example this code should work:
    [code2=cpp]x = ValueObject<int>(ev->getValue(POS_X)).getDataCopy();[/code2]
  • It works fine now, thank you!
  • I am having trouble sending hashtables across to other players using the Photon cloud server. I am using the Marmalade SDK. The example project only uses passing objects, not has tables.

    Here's my test code: I am sending

    const nByte POS_X = 101;
    int x = 1;
    ev.put(POS_X, x);
    mLoadBalancingClient.opRaiseEvent(false, ev, 101);

    On the receiving side,

    void NetworkLogic::customEventAction(int playerNr, nByte eventCode, const ExitGames::Common::Hashtable& eventContent)
    {
    const nByte POS_X = 1, POS_Y = 102, key2 = 103;
    int x;
    int myInt;
    int command;
    switch ((int)eventCode) {
    case 0:
    break;
    case 1:
    break;
    case 101:
    // nByte key and int value:
    if (eventContent.getValue((POS_X)))
    x = ExitGames::Common::ValueObject<int>(eventContent.getValue(POS_X)).getDataCopy();

    break;

    }
    }

    The function (eventContent.getValue((POS_X)) produces an access viotation exception.

    I tried using ev.put(KeyObject<nByte>(POS_X), ValueObject<int>(x)); In that case, I get an ERROR_UNSUPPORTED_KEY_TYPE compilation error.

    Any help would be much appreciated.

    Thanks!
  • Hi swarnamuki.
    I tried using ev.put(KeyObject<nByte>(POS_X), ValueObject<int>(x)); In that case, I get an ERROR_UNSUPPORTED_KEY_TYPE compilation error.
    This is to be expected.

    This was the old pre 3.0.4.0 way of putting entries into a Hashtable. With 3.0.4.0 we have simplified the put() API, so since then one directly passes the values to put() instead of first wrapping them into Key- and ValueObjects.

    Your send code looks absolutely fine.

    What SDK version are using?
    I have tested your code with the 3.2.2.2 SDK release (from your code it appears to me, that you must be using a release around 3.0.2.x, as your code isn't compatible to 3.0.4.x, nor to 3.2.x) and it works just fine. I can't reproduce your crash.
    However I found one bug in your code: in your send code POS_X gets set to 101 and in your receive code it is set to 1, but even that doesn't produce a crash, because in that case the if-condition doesn't return true and the code line for which you repeat a crash doesn't even get executed.