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

Author Topic: sfTime allways have zero value  (Read 3631 times)

0 Members and 3 Guests are viewing this topic.

Saw

  • Newbie
  • *
  • Posts: 11
    • View Profile
sfTime allways have zero value
« on: March 05, 2023, 04:55:57 pm »
I assign a value to a variable ways, but in the debugger the value is always 0.
In theory, everything should work. Maybe I'm doing something wrong?

sfTime time1 = sfSeconds(0.1f) ;
sfTime time2 = sfMilliseconds(100000);

CSFML 2.5.1
C++ Builder 11.3

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sfTime allways have zero value
« Reply #1 on: March 05, 2023, 05:16:28 pm »
What value do you look at in your debugger? How are you debugging it?
What if you say print it to a console?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Saw

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sfTime allways have zero value
« Reply #2 on: March 05, 2023, 05:57:35 pm »
I'll try to attach the image

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sfTime allways have zero value
« Reply #3 on: March 05, 2023, 06:09:48 pm »
If you break at the line of assignment, the internal value will be zero, because it hasn't been assigned yet.
If you go one step forward, you should see the value change, as it passed the assignment line ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Saw

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sfTime allways have zero value
« Reply #4 on: March 05, 2023, 06:26:12 pm »
Ok. 4 variables.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sfTime allways have zero value
« Reply #5 on: March 05, 2023, 07:51:21 pm »
Are the values also 0 if you access them, e.g. print them to the console?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Saw

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sfTime allways have zero value
« Reply #6 on: March 05, 2023, 09:52:54 pm »
Yes. If I try to withdraw these variables, then
And in the debugger and on the screen, the value is 0.
I have not noticed any problems anymore. The remaining variables are displayed correctly.

char c_test[10];
float aaa = test1.microseconds ;
sprintf(c_test, "%f", aaa);
sfText_setString(Show_Message,  c_test );
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sfTime allways have zero value
« Reply #7 on: March 05, 2023, 11:48:00 pm »
Didn't exactly want to setup CSFML and all, so I copied the CSFML code and it seems to work just fine: https://onlinegdb.com/vbZRwUfIe

Can you create a minimal and complete example, that reproduces the issue (with main() and everything)?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Saw

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sfTime allways have zero value
« Reply #8 on: March 06, 2023, 12:48:13 am »
I think the problem is not in the code itself. I am using C++Builder 11.x. To do this, we need to convert the .lib files to the coff format.
The .lib file is exported from dll. For some reason, the .lib files from the distribution are not being converted.
Maybe there's some problem here.

Saw

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sfTime allways have zero value
« Reply #9 on: March 07, 2023, 01:23:54 am »
I tried to make a small example.
The problem of an empty variable is not clear yet. In a small example, something works. I don't even know why. I will analyze. But even in this small example, a lot of questions arose. Maybe I'm doing something wrong.
1. It is not clear why two identical variables produce a different value.
2. It is not clear how the sfClock_getElapsedTime function works
She's always returns the same value.
It seems that CSFML does not work like SFML ...
I'll test a little more, but I haven't won the time functions yet.
If necessary, I can post the project and the .exe file.


#pragma argsused


#include <Windows.h>
#include <stdio.h>

#pragma hdrstop


#include <SFML/Graphics.h>

#pragma link "csfml-system.lib"
#pragma link "csfml-window.lib"
#pragma link "csfml-graphics.lib"

int main()
{

        sfRenderWindow *window;
        sfVideoMode mode= {800, 600, 32};

        window = sfRenderWindow_create(
                mode ,
                "Test",
                sfResize | sfClose | sfTitlebar | sfClose,
                NULL );

        if (!window) return EXIT_FAILURE ;


        sfFont *font1 = sfFont_createFromFile("resources/sansation.ttf") ;
        sfFont *font2 = sfFont_createFromFile("resources/sansation.ttf") ;
        if (!font1 ) return EXIT_FAILURE;
        if (!font2 ) return EXIT_FAILURE;

        sfText *message1 = sfText_create();
        sfText_setFont(message1, font1);
        sfText_setCharacterSize(message1, 40);
        sfText_setFillColor(message1, sfWhite);

        sfText *message2 = sfText_create();
        sfText_setFont(message2, font2);
        sfText_setCharacterSize(message2, 40);
        sfText_setFillColor(message2, sfWhite);

        sfClock *clock = sfClock_create();
        sfClock_restart(clock) ;


        sfTime test1 = sfMicroseconds(100000);
        sfTime test2 = sfMicroseconds(100000);



        while (sfRenderWindow_isOpen(window) )
        {
                sfEvent event;
                while (sfRenderWindow_pollEvent(window, &event))
                {
                        if ((event.type == sfEvtClosed) ||
                           ((event.type == sfEvtKeyPressed) && (event.key.code == sfKeyEscape)))
                        {
                                sfRenderWindow_close(window);
                                break;
                        }
                }


//      float time = sfTime_asSeconds( sfClock_restart(clock) ) ;  // update timer
//      float ftest1 = time ;

        float ftest1 =  test1.microseconds ;

        char c_test1[10];
        sprintf(c_test1, "%f", ftest1);

        sfVector2f sfTextPos1 = {50.f , 100.f };
        sfText_setPosition(message1, sfTextPos1 );
        sfText_setString(message1,  c_test1 );

        char c_test2[10];
        float  ftest2 = test2.microseconds ;
        sprintf(c_test2, "%f", ftest2);

        sfVector2f sfTextPos2 = {50.f , 150.f };
        sfText_setPosition(message2, sfTextPos2 );
        sfText_setString(message2,  c_test2 );


        sfRenderWindow_clear(window, sfColor_fromRGB(50, 200, 50));
        sfRenderWindow_drawText(window, message1,  NULL);
        sfRenderWindow_drawText(window, message2,  NULL);
        sfRenderWindow_display(window);

         }

        sfClock_destroy(clock);
        sfText_destroy(message1);
        sfText_destroy(message2);
        sfFont_destroy(font1);
        sfFont_destroy(font2);
        sfRenderWindow_destroy(window);

        return EXIT_SUCCESS;
}