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

Author Topic: Run-Time Check Failure and something  (Read 3970 times)

0 Members and 3 Guests are viewing this topic.

Ignoscite Mihi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • My music
    • Email
Run-Time Check Failure and something
« on: May 13, 2015, 10:31:53 pm »
Hi guyz!

At the beggining I want to provide you that I've google my problem and did't get solve.
So.. I am working on a rpg game and update my old VS 10 to 12 and SFML 2.2 to 2.3.
Firstly I'm getting now random "Run-Time Check Failure #2" becouse of Font,Text, Music and Thread. Sometimes is working fine and error is appearing when I close my program.

Font and Text:
http://wklej.org/id/1710918/

Thread and Music:
http://wklej.org/id/1710942/

Secondly after update my buttons don't work.

if(text.getGlobalBounds().contains(mouse) && event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left)
//code here

It's working only when i delete:
 
event.type == Event::MouseButtonReleased
But then mouse is hiting 2 times.

Could someone help me?
You can find my music here: https://www.facebook.com/nativefiremusic

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Run-Time Check Failure and something
« Reply #1 on: May 13, 2015, 11:26:44 pm »
There is no event.key.code defined when event.type is MouseButtonReleased.
Check the tutorial, you're supposed to use event.mouseButton.button

Ignoscite Mihi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • My music
    • Email
Re: Run-Time Check Failure and something
« Reply #2 on: May 14, 2015, 08:23:26 am »
I'm using
else if(text.getGlobalBounds().contains(mysz) && event.type == Event::MouseButtonReleased && event.mouseButton.button == Mouse::Left)
and still don't working.

EDIT:
I changed
Event::MouseButtonReleased
to
Event::MouseButtonPressed
and it's working but I expect to do something when i release button.

EDIT2:
In first post I forgot to tell you that music isn't playing.

EDIT3: However
Event::MouseButtonPressed
is working like
Event::MouseButtonReleased
.
« Last Edit: May 14, 2015, 08:35:30 am by Ignoscite Mihi »
You can find my music here: https://www.facebook.com/nativefiremusic

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Run-Time Check Failure and something
« Reply #3 on: May 14, 2015, 10:44:29 am »
Your thread or playmusic() dies instantly: music doesn't have enough time to play. You have to keep it alive.

Why goto...? Things you declared inside a block won't get properly cleaned up if you exit the block with a goto.

Ignoscite Mihi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • My music
    • Email
Re: Run-Time Check Failure and something
« Reply #4 on: May 14, 2015, 07:54:24 pm »
I think I don't understand you :/ I always was about the thread is keeping music alive.

EDIT:
Okay so I delete all
goto EXIT;
and there is no Run-Time Check Failure yet.
« Last Edit: May 14, 2015, 07:59:26 pm by Ignoscite Mihi »
You can find my music here: https://www.facebook.com/nativefiremusic

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Run-Time Check Failure and something
« Reply #5 on: May 14, 2015, 10:51:37 pm »
Why is the font getting created and loaded on every cycle in the main loop? It should be created and loaded before the loop so it only gets loaded once. It wouldn't hurt to take the text object out of the loop too ;)
(click to show/hide)

If you insist on using goto to exit the loop instead of just setting a to false, there's no reason to use the a variable; you can just loop with while (true) since the goto is the only way to exit that loop.
You could just change
goto EXIT;
to
a = false;
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Ignoscite Mihi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • My music
    • Email
Re: Run-Time Check Failure and something
« Reply #6 on: May 15, 2015, 06:34:41 am »
I changed
goto EXIT;
to
window.close();
and program after close window is running. After I added order to close program Run-Time error is appearing again.

Quote
Why is the font getting created and loaded on every cycle in the main loop? It should be created and loaded before the loop so it only gets loaded once. It wouldn't hurt to take the text object out of the loop too

Becouse it's fast-made program. In my main project where all declarations are before loop Run-Time Check Failure is also appearing.
You can find my music here: https://www.facebook.com/nativefiremusic

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Run-Time Check Failure and something
« Reply #7 on: May 15, 2015, 10:28:47 am »
That's because a still equals true. If you do what Hapax said then it should solve the problem. Just because the window is gone, it doesn't mean that all loops will automatically stop. If you want to end your program using window.close(), you need to put window.isOpen() as your loop condition.

Ignoscite Mihi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • My music
    • Email
Re: Run-Time Check Failure and something
« Reply #8 on: May 15, 2015, 04:39:58 pm »
That's because a still equals true. If you do what Hapax said then it should solve the problem. Just because the window is gone, it doesn't mean that all loops will automatically stop. If you want to end your program using window.close(), you need to put window.isOpen() as your loop condition.

You are right. I had written that after I added order to close program (x = false) a Run-Time Check Failure is still appearing :)
You can find my music here: https://www.facebook.com/nativefiremusic

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Run-Time Check Failure and something
« Reply #9 on: May 15, 2015, 04:46:57 pm »
A quick google just told me that the error is usually when you are accessing part of an array that doesn't exist (is out of bounds). I couldn't see that in the code you'd given but I know you omitted some things so it might be in there. Basically the error means you are accessing something that doesn't exist when you access it.
EDIT: I wasn't sure whether you had completely solved the problem or whether it had just stopped coming up for the moment and this seemed like useful information so it doesn't happen again.
« Last Edit: May 15, 2015, 04:51:10 pm by shadowmouse »

Ignoscite Mihi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • My music
    • Email
Re: Run-Time Check Failure and something
« Reply #10 on: May 15, 2015, 08:55:41 pm »
A quick google just told me that the error is usually when you are accessing part of an array that doesn't exist (is out of bounds). I couldn't see that in the code you'd given but I know you omitted some things so it might be in there. Basically the error means you are accessing something that doesn't exist when you access it.
EDIT: I wasn't sure whether you had completely solved the problem or whether it had just stopped coming up for the moment and this seemed like useful information so it doesn't happen again.
Problem is not solved.
You can find my music here: https://www.facebook.com/nativefiremusic

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Run-Time Check Failure and something
« Reply #11 on: May 15, 2015, 09:16:06 pm »
My recommendations would be:

1. Use a debugger to inspect the objects/variables/addresses involved in the crash and see if what is actually happening matches your expectations of what should happen.

2. Turn your compilers warning level up and fix the issues it points you at.

3. Use tools like address sanitizer and Valgrind to detect bugs in your code.

4. Stop using threads. Threads are hard to get right and introduce a huge amount of complexity and potential problems and you don't strike me as nearly experienced enough to be playing around with such advanced tools.

5. Read up (more) on C++ - I get the impression that things like object lifetimes, RAII and similar are foreign to you and may be the root cause of your problems.
« Last Edit: May 15, 2015, 09:18:24 pm by Jesper Juhl »

Ignoscite Mihi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • My music
    • Email
Re: Run-Time Check Failure and something
« Reply #12 on: May 16, 2015, 11:19:13 am »
Okey guyz problem is solved.  ;D Only what I have done was delete visual studio and all components and install it again. I know it sounds stupid. Anyway thanks all for help :)
You can find my music here: https://www.facebook.com/nativefiremusic

 

anything