Skip to main content
Inspiring
February 28, 2017
Answered

Is it bad practice to have the src and dst worlds the same for transform_world?

  • February 28, 2017
  • 1 reply
  • 516 views

Is it bad practice to have the src and dst worlds the same for transform_world? Sometimes it feels like it’s causing glitchy behaviour and other times not. Though I may be mistaken and something else could be causing the glitches.

I'm wondering because I don't know where it would store all the pixels whilst it's transforming them. Thanks!

This topic has been closed for replies.
Correct answer Christian Lett

I wouldn't, just because of "race conditions" if transform_world is multi-threaded (if the process is split over, say, four threads then thread 2 might reference a part of the world that's already been transformed by thread 1).

Just create a temp world and use PF_Copy to copy the contents of src over (it's quick, since it's just a memcpy if using no rects), then use the temp world as your src in transform_world. You can dispose of the temp world immediately after the transform_world has completed.

As and aside, I'm not sure if transform_world keeps the old pixels outside of the destination rect. So you might be better off filling the dest with empty pixels before transform_world, just to be sure.

1 reply

Christian LettCorrect answer
Inspiring
March 1, 2017

I wouldn't, just because of "race conditions" if transform_world is multi-threaded (if the process is split over, say, four threads then thread 2 might reference a part of the world that's already been transformed by thread 1).

Just create a temp world and use PF_Copy to copy the contents of src over (it's quick, since it's just a memcpy if using no rects), then use the temp world as your src in transform_world. You can dispose of the temp world immediately after the transform_world has completed.

As and aside, I'm not sure if transform_world keeps the old pixels outside of the destination rect. So you might be better off filling the dest with empty pixels before transform_world, just to be sure.

Inspiring
March 3, 2017

Thanks Christian, that makes total sense now!