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

Author Topic: Sprite draw crash.  (Read 6843 times)

0 Members and 1 Guest are viewing this topic.

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Sprite draw crash.
« on: April 18, 2012, 12:58:22 pm »
At certain points during a debug run, the program will stop, and return a nullobjectexception in the Transform.Combine function that is being called during the RenderWindow.Draw(Sprite) function (in the first line of the Sprite.Draw(RenderTarget target, RenderStates states) function). The null object is the transform.

Now, as far as I can see, the Sprite & Texture behind the sprite aren't null, and I don't see any recurring events which lead to this, so I've failed to find the source of the error. Any idea?
« Last Edit: April 18, 2012, 01:07:44 pm by nihohit »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sprite draw crash.
« Reply #1 on: April 18, 2012, 01:09:22 pm »
Does it happen with the OpenGL example application?
Laurent Gomila - SFML developer

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Sprite draw crash.
« Reply #2 on: April 18, 2012, 10:59:35 pm »
No, in my own program, with no OpenGL at all.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Sprite draw crash.
« Reply #3 on: April 19, 2012, 12:02:44 am »
No, in my own program, with no OpenGL at all.

Laurent meant the example that comes with the library.

A 'wild' guess do you define that sprite as global or before the window gets created?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Sprite draw crash.
« Reply #4 on: April 19, 2012, 07:07:44 am »
Yes, I didn't run the OpenGL example program. I tried once and errors popped ("output path not defined"), and since I wasn't interested in OpenGL didn't bother with it.

There's no global sprite. There's one that is created before the window, but it gets displayed well - it's the background, and the program runs and displays stuff (and the background) before crashing. It happens when drawing new sprites.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sprite draw crash.
« Reply #5 on: April 19, 2012, 08:11:31 am »
Can you show a complete and minimal example that reproduces the problem please?
Laurent Gomila - SFML developer

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Sprite draw crash.
« Reply #6 on: April 19, 2012, 11:17:48 am »
Argh. This is a problem that spans the interaction between several objects and threads. I can try to minimise it, but will it still be worthwhile if the code I'll upload will be quite long?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sprite draw crash.
« Reply #7 on: April 19, 2012, 12:12:40 pm »
Do you really need the same complexity to reproduce it? I mean, if it's a bug in SFML then it can probably be reproduced easily. If not, then the problem is caused by your program, and there's nothing I can do.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Sprite draw crash.
« Reply #8 on: April 19, 2012, 01:56:42 pm »
... several objects and threads...

Do you handle your OpenGL context in the right way? (You need to activate the contex in the thread you're working with graphics)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Sprite draw crash.
« Reply #9 on: April 19, 2012, 09:46:14 pm »
Do you really need the same complexity to reproduce it? I mean, if it's a bug in SFML then it can probably be reproduced easily. If not, then the problem is caused by your program, and there's nothing I can do.

Oh, I don't know what I need to reproduce it. Currently it's very complex, and I'll try to focus on the minimal needed to reproduce it.

eXpl0it3r - I don't use OpenGL, but I do set it to Active(false) on the thread it's created.
« Last Edit: April 19, 2012, 09:48:09 pm by nihohit »

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Sprite draw crash.
« Reply #10 on: April 19, 2012, 11:01:44 pm »
I'm still looking at reducing the code, but now I've noticed that the only null part of the Sprite is myInverseTransform, and that under InverseTransform there's a message "'((SFML.Graphics.Transformable)(sprite)).InverseTransform' threw an exception of type 'System.AccessViolationException'   SFML.Graphics.Transform {System.AccessViolationException}".

Is this a hint towards what happened?

EDIT: I now see that every object has it as null. So I don't see what do I get the null exception on - the Sprite's definitely not a null, and I can't seem to reduce this to a minimal case that wtill pops the error.
« Last Edit: April 20, 2012, 07:54:51 am by nihohit »

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Sprite draw crash.
« Reply #11 on: April 20, 2012, 09:47:26 am »
So, to explain why I failed to find a minimal working problem - apparently it's not the Texture, or the original images - Sprites made from both are running. There's no discernible cause for this, no condition that I could isolate through prints, etc. Frankly, at the level of information open to me, I can't discern any difference between the Sprites that crash (and they're very few) and those that don't.

The only thing I know is that sometimes, when calling line 165 in Sprite.Draw, states.Transform *= Transform, the "right" variable will be null. Since this.Transform isn't null, but is Matrix(System.Single)[], I don't really understand what is happening.
« Last Edit: April 20, 2012, 09:53:26 am by nihohit »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sprite draw crash.
« Reply #12 on: April 20, 2012, 09:58:42 am »
After looking at the source code again, I can tell you that the Transform member of the sprite cannot be null. The only way it can be null is if the same sprite object is manipulated from several threads concurrently -- the Sprite class is not thread-safe.
Laurent Gomila - SFML developer