Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning an enum struct gives incorrect member variable values #1012

Closed
Bradasparky opened this issue Nov 29, 2024 · 1 comment
Closed

Returning an enum struct gives incorrect member variable values #1012

Bradasparky opened this issue Nov 29, 2024 · 1 comment

Comments

@Bradasparky
Copy link

Bradasparky commented Nov 29, 2024

Details

OS: Windows 10
Compiler Version: 1.13.0.7177
Server Version: TF2 32-bit

Description

When trying to return an enum struct from a function which initializes variables, it sets all of them to 0 on the first run. Calling the function again to get a new struct will initializes variables properly or improperly depending on the position that they're declared within the struct.

Test Case

enum struct MyStruct
{
    int v;
    float f;
    char sz[8];
}

MyStruct CreateStruct()
{
    MyStruct st;
    st.v = 1;
    st.f = 1.0;
    st.sz = "Hello";
    return st;
}

void PrintStruct(MyStruct st)
{
    PrintToServer("%i", st.v);
    PrintToServer("%f", st.f);
    PrintToServer("%s", st.sz);
}

public void OnPluginStart() 
{
    PrintToServer("\nFirst Struct");
    MyStruct st;
    st = CreateStruct();
    PrintStruct(st);
    st = CreateStruct();
    PrintStruct(st);
    st = CreateStruct();
    PrintStruct(st);
    PrintToServer("\nNew Struct Below");
    MyStruct st2;
    st2 = CreateStruct();
    PrintStruct(st2);
    st2 = CreateStruct();
    PrintStruct(st2);
    st2 = CreateStruct();
    PrintStruct(st2);
}

Log

First Struct
0
0.000000

2988
1.000000
Hello
2988
1.000000
Hello

New Struct Below
0
0.000000

2988
1.000000
Hello
2988
1.000000
Hello
dvander added a commit that referenced this issue Nov 30, 2024
Bug: issue #1012
Test: new test case
dvander added a commit that referenced this issue Nov 30, 2024
Bug: issue #1012
Test: new test case
@dvander
Copy link
Member

dvander commented Nov 30, 2024

Thanks, this has been fixed on master.

@dvander dvander closed this as completed Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants