Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Codeblocks ported to sqrat

<< < (3/11) > >>

BlueHazzard:
Hi!
i have found a bug. A very strange bug. Can please someone review this code, if it is right:

--- Code: ---template<>
struct Var<const wxString&> {
    const wxString& value;
    wxString tmp_value;
    Var(HSQUIRRELVM v, SQInteger idx) : value(tmp_value){
        if (!Sqrat::Error::Instance().Occurred(v)) {
            wxString* ptr = ClassType<wxString>::GetInstance(v, idx);
            if (ptr != NULL) {
                tmp_value.Append((*ptr).c_str());
            } else {
                Sqrat::Error::Instance().Clear(v);
                const SQChar* str;
                sq_tostring(v, idx);
                sq_getstring(v, -1, &str);
                tmp_value = wxString::FromUTF8(str);
                sq_pop(v, 1);
            }
        }
    }
    static void push(HSQUIRRELVM v, const wxString& value) {
        ClassType<wxString>::PushInstanceCopy(v, value);
    }
};
--- End code ---
i need the member value to be a const ref to a wxString.

On linux this code works without problems on windows it worked with gcc 4.7 but with 4.8 the value overwrites some other variables in the code.
You can reproduce it with this steps:

--- Code: ---1. Compile c::b from my git hub repo
2. Set breakpoint at "include/scripting/sqrat/sqrat/sqratGlobalMethodes.h" at line 184 and 185
3. Start the debugger
4. load the script "scripts/ConvertOldToNewScript.script"
5. run the script from menu plugins->Convert Scripts
5b. if a messagebox pops up press ok
6. The debugger will now stop on breakpoint 1: Look at the variable "method". It will hold the right address for the function "wx_GetFileFromUser"
7. Continue the debugger one line, it will stop on breakpoint 2
8. The pointer "method" does not point anymore to a valid function....

--- End code ---

after investigating i found the error in the source posted previously. The address gets changed at the initialization of the reference in the first line of the constructor...

i have no clue why, or how i should fix this, because for me the code looks ugly but right...

greetings

oBFusCATed:
Why do you need tmp_value and value? This seems quite odd.
You have to talk to a c++ expert but I suppose the value(tmp_value) initialization is an undefined behaviour, because the members are initialized in the order they are declared, not the order you use them in the initializer list. So you're initializing value to be a reference to uninitialized object.

If you can reorder the members, you could try it.

BlueHazzard:
i tried it, but now it crashes in on a other place, and i haven't discovered yet where....
funny....

oBFusCATed:
Do you know why you need the reference?

BlueHazzard:
I have fixed the error. It was interesting: When i debugged the source, it jumped in the right specialized template function, but if i printed the value type outside specialized  the function it showed me the wrong type. On the end i had to include the header file to the right places... it is pretty tricky to find such a error, without compiler warning, and also the right programflow, but perhaps with a wrong value interpretation...

still waiting for test results with bigger script plugins ;)

new added:

* wxBell
* wxDirSelector
* wxMessageBox
greetings

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version