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

Author Topic: Passing a sf::Texture instance to a function is slow  (Read 1335 times)

0 Members and 1 Guest are viewing this topic.

sheep

  • Newbie
  • *
  • Posts: 2
    • View Profile
Passing a sf::Texture instance to a function is slow
« on: May 11, 2013, 07:17:05 am »
Hi guys.. first time poster..

I recently started using sfml and i seem to have come across a rather odd bug.. one that took me a little while to track down i may add :(

Im not new to c++ but it has been a few years since i coded in it..

so this may not be SFML's fault.. but ill explain and u can decide..

I started off by creating a class for my player.. i put an sf::Texture as one of its public variables..

now.. if i dont do anything with this texture, its fine..  i can pass the class to functions as much as i want and no errors.. the problem comes when i use

SF::TEXTURE.loadFromFile

no matter WHERE i load it from, INSIDE or OUTSIDE of the class.. once that texture has been initialised with that call.. i can no longer pass it to a function without INCREDIBLE slow down..

i did a small test, i placed a for loop with 900 cycles - inside it i placed a function that did literally NOTHING..

I then removed the code that initiated the texture with SF::Texture.LoadFromFile

i passed my CLASS to the function and ran the code, onscreen my little man runs around fine and smooth.

If i then put the code back to normal and let the texture initialise with the .LoadFromFile it basically stops my game running. I wondered if anyone else had come across this problem??

ill try and show a little better with some code.. just incase its confusing..


//Init code (ran only once at start of program)
sf::Texture MyText;   

MyText.loadFromFile("sheet2.png");   // If i comment this out, it runs fine...
                                                           // If i leave it in then its slow..


// loopy test.

for (int p=0;p < 900;p++)
{

Redundant_func(MyText);

};


« Last Edit: May 11, 2013, 09:39:40 am by Laurent »

Cornstalks

  • Full Member
  • ***
  • Posts: 180
    • View Profile
    • My Website
Re: SFML - SF::TEXTURE BUG...
« Reply #1 on: May 11, 2013, 07:48:00 am »
Are you passing the texture by reference? If you're not, you're going to be creating copies, which is a slow and expensive process (and should be avoided when possible).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Passing a sf::Texture instance to a function is slow
« Reply #2 on: May 11, 2013, 09:40:54 am »
Quote
first time poster..
Welcome. Next time, please take 5 minutes to search the right forum to post to, and to choose a meaningful title :)
Laurent Gomila - SFML developer

sheep

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Passing a sf::Texture instance to a function is slow
« Reply #3 on: May 11, 2013, 03:19:04 pm »
hey man.. yeah sorry about that.. didnt mean to be a scare monger.. couldnt think of any other title at the time(5am) ;p .. will check better next time.. i assumed it would have been more ignorance on my part than a bug on urs.. great library.. tnx for the effort and time you put in..

cheers matey..

hey corn - tnx for reply m8y
« Last Edit: May 11, 2013, 03:20:53 pm by sheep »