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

Author Topic: SetPixel() method throws AccessViolationException (VS)  (Read 2240 times)

0 Members and 1 Guest are viewing this topic.

Tigre Pablito

  • Full Member
  • ***
  • Posts: 226
    • View Profile
    • Email
SetPixel() method throws AccessViolationException (VS)
« on: December 02, 2017, 07:43:48 pm »
Hello Ladies and Guys

SetPixel() method from Image class throws an AccessViolationException in my poor Super Mario Game, and that had never happened before. I tried to think why it happens, and thought maybe it could be because the image which pixels are drawn to is inside a Texture that is currently in use in the game. But why now, if it had never happened before? The issue occurs when Mario hits a block and it remains out of items (coins, mushrooms, etc), that the program stops drawing the "animated" block and draws the empty hard block (draws on the level image that is in memory) and sets the level hardness attributes of all its pixels to SOLID. And this happens not at the first block, but at the 5th or 6th.

Any help will be appreciated

 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SetPixel() method throws AccessViolationException (VS)
« Reply #1 on: December 02, 2017, 07:48:20 pm »
We won't be able to help you with a textual description of your problem, no code and no clue.

Did you run your debugger?
-> yes: give us more information (location of the crash, call stack, local variables)
-> no: do (learn?) it :)
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: SetPixel() method throws AccessViolationException (VS)
« Reply #2 on: December 02, 2017, 09:02:37 pm »
Also make sure x and y are inside the image's size you're trying to draw on.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tigre Pablito

  • Full Member
  • ***
  • Posts: 226
    • View Profile
    • Email
Re: SetPixel() method throws AccessViolationException (VS)
« Reply #3 on: December 02, 2017, 09:05:56 pm »
Hi Laurent

I removed the code that drew the fixed block to the Image and the app worked fine (it's drawn every loop, no need of SetPixel())

Sorry for the bother

And I like the funny stuff ... Yes, I know debugging, but sometimes it's not so easy in large and sophisticated programs  :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SetPixel() method throws AccessViolationException (VS)
« Reply #4 on: December 02, 2017, 09:09:54 pm »
Quote
sometimes it's not so easy in large and sophisticated programs
But still, in any case it gives a much better starting point than "it crashes and I don't know why". So please use it, especially when you're about to ask for help on a forum ;)
Laurent Gomila - SFML developer

Tigre Pablito

  • Full Member
  • ***
  • Posts: 226
    • View Profile
    • Email
Re: SetPixel() method throws AccessViolationException (VS)
« Reply #5 on: December 03, 2017, 12:56:54 am »
Hi eXpl0it3r

It seems that you sent your message while I was writting my last one. Thanks. I don't think it was "IndexOutOfRange", ... but anyway, I already solved the issue just removing the "buggy" code.

Laurent

I'll keep in mind to run the debugger before posting ... Thanks