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

Author Topic: Problem with program crashing as soon as activated  (Read 3582 times)

0 Members and 1 Guest are viewing this topic.

Frostbite

  • Newbie
  • *
  • Posts: 17
    • View Profile
Problem with program crashing as soon as activated
« on: February 24, 2010, 08:33:35 am »
I am using MinGW as far as I know (I'm actually not too knowledgeable on that) And the problem is that whenever I compile and run the program crashes immediately, the window does pop up, but shows nothing. The first ten times this happened it slowed down my computer considerably, now it just shows up as a regular non-responsive program.

Here are my build messages and build log, I think they have the reason for the problem. Ask if you need any other information.


Build Messages:
Code: [Select]

||Info: resolving vtable for sf::Spriteby linking to __imp___ZTVN2sf6SpriteE |
||Info: resolving vtable for sf::Drawableby linking to __imp___ZTVN2sf8DrawableE |
||warning: auto-importing has been activated without --enable-auto-import specified on the command line.|
||=== Build finished: 0 errors, 1 warnings ===|



Build Log:
Code: [Select]

Compiling: C:\Users\Mike\Desktop\Projects\Xep\source1.cpp
Linking console executable: C:\Users\Mike\Desktop\Projects\Xep\source1.exe
Info: resolving vtable for sf::Spriteby linking to __imp___ZTVN2sf6SpriteE (auto-import)
Info: resolving vtable for sf::Drawableby linking to __imp___ZTVN2sf8DrawableE (auto-import)
C:\Program Files (x86)\CodeBlocks\MinGW\bin\ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 1 warnings
 
Checking for existence: C:\Users\Mike\Desktop\Projects\Xep\source1.exe
Executing: C:\Program Files (x86)\CodeBlocks/cb_console_runner.exe "C:\Users\Mike\Desktop\Projects\Xep\source1.exe" (in C:\Users\Mike\Desktop\Projects\Xep)
Process terminated with status -1073741510 (1 minutes, 3 seconds)
 


Thank you again. The sfml forums are some of the best when it comes to help and support. I am really appreciative ahead of time.



------Edit--------
Oh and I just realized it would be a good idea to mention this,  I have other SFML games that compile and run just fine on my computer. They use the same .dll's and the same linker and compiler. I guess this means the problem must be in the code somewhere. I just have no clue where.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem with program crashing as soon as activated
« Reply #1 on: February 24, 2010, 08:58:20 am »
Can you show your code? Have you tried the samples provided in the SDK?

Quote
Here are my build messages and build log, I think they have the reason for the problem

No, this is not related. It's because you forgot to define SFML_DYNAMIC (it is explained in the "getting started" tutorial).
Laurent Gomila - SFML developer

Frostbite

  • Newbie
  • *
  • Posts: 17
    • View Profile
Problem with program crashing as soon as activated
« Reply #2 on: February 24, 2010, 09:04:04 am »
Here are all the parts pertaining to SFML, as far as I can tell at least,



Code: [Select]

#include <iostream>
#include <fstream>
#include <string>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

using namespace std;

/// Entry point of application
///
/// \return Application exit code
///
//------------------------------SF stuff------------------------------------------
    sf::RenderWindow Window(sf::VideoMode(650, 400, 32), "Avian");
    sf::Clock Clock;
    sf::Image ZepImage;
    sf::Image BG1Image;
    sf::Image BG2Image;
    sf::Image BG3Image;
    sf::Image BG4Image;
//--------------------------End SF stuff------------------------------------------

class CannonBall{
    public:
    float mass;
    float X;
    float Y;
    float VelX;
    float VelY;
};

class Zepplin{
    public:
    float X;
    float Y;
    float BattleX;
    float BattleY;
    float Speed;
    float Health;
    sf::Sprite ZepSprite;
    CannonBall Balls[10];
}PlayerZepplin;

int WKeyDown(){
    if(Window.GetInput().IsKeyDown(sf::Key::W)){
        return 1;
    }
}
int SKeyDown(){
    if(Window.GetInput().IsKeyDown(sf::Key::S)){
        return 1;
    }
}
int AKeyDown(){
    if(Window.GetInput().IsKeyDown(sf::Key::A)){
        return 1;
    }
}
int DKeyDown(){
    if(Window.GetInput().IsKeyDown(sf::Key::D)){
        return 1;
    }
}

float GetTime(){
    return Clock.GetElapsedTime();
}
float Time;

class Background{
    public:
    sf::Sprite BGSprite;
    float X;
    float Y;
}BG1, BG2, BG3, BG4;

void ScrollBG(Background BG){
    if (!(BG.X < -210)){ //if the BG isn't very far left
        BG.X = BG.X - 2;
    }
    else{
        BG.X = 1390;//three 400 -210, allows four different backgrounds
    }
}

void ZepBattle(){
    int BattleOn = 4;
    while (BattleOn){
        while (Window.IsOpened()){
        Time = GetTime();
        Window.Clear();
        //---------------------------------------------------------------
        if (WKeyDown()){
            PlayerZepplin.BattleY = PlayerZepplin.BattleY + ((20 * (Time/GetTime())) * PlayerZepplin.Speed);
        }
        if (SKeyDown()){
            PlayerZepplin.BattleX = PlayerZepplin.BattleX - ((20 * (Time/GetTime())) * PlayerZepplin.Speed);
        }
        if (AKeyDown()){
            PlayerZepplin.BattleX = PlayerZepplin.BattleX - ((20 * (Time/GetTime())) * PlayerZepplin.Speed);
        }
        if (DKeyDown()){
            PlayerZepplin.BattleX = PlayerZepplin.BattleX + ((20 * (Time/GetTime())) * PlayerZepplin.Speed);
        }
        //---------------------------------------------------------------

        ScrollBG(BG1);
        ScrollBG(BG2);
        ScrollBG(BG3);
        Window.Draw(BG1.BGSprite);
        Window.Draw(BG2.BGSprite);
        Window.Draw(BG3.BGSprite);
        Window.Draw(BG4.BGSprite);
        Window.Draw(PlayerZepplin.ZepSprite);
        Window.Display();
        }
        }

    }

void Initalize(){
    if(!ZepImage.LoadFromFile("Zep.png"))
    PlayerZepplin.ZepSprite.SetImage(ZepImage);
    PlayerZepplin.ZepSprite.SetCenter(9.5f,9.5f);
    PlayerZepplin.ZepSprite.SetPosition(200,200);
    PlayerZepplin.Speed = .95f;
    if(!BG1Image.LoadFromFile("BG1.png"))
    if(!BG2Image.LoadFromFile("BG2.png"))
    if(!BG3Image.LoadFromFile("BG3.png"))
    if(!BG4Image.LoadFromFile("BG4.png"))
    BG1.BGSprite.SetImage(BG1Image);
    BG2.BGSprite.SetImage(BG2Image);
    BG3.BGSprite.SetImage(BG3Image);
    BG4.BGSprite.SetImage(BG4Image);
}

void Menu(){
}

int main(){

    Initalize();
    Menu();
    ZepBattle();


}



I apologize for putting it all in there, I just don't know another way to do it.

Also, no I haven't looked at the Code::Blocks page, it really didn't occur to me. THough I don't know what I would be looking for.

Frostbite

  • Newbie
  • *
  • Posts: 17
    • View Profile
Problem with program crashing as soon as activated
« Reply #3 on: February 24, 2010, 09:10:13 am »
I just compiled it again and its doing something completely different... It shows me the white dots that are placeholders for images, and the buttons don't work, but it isn't crashing. And the above two problems I could probably fix myself.

Its really strange. But I don't really think there is a problem anymore.


----edit----
And once again its crashing, but everything loads, so its probably ok

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem with program crashing as soon as activated
« Reply #4 on: February 24, 2010, 09:11:36 am »
Have you tried not creating your SFML window before main() is executed? Global objects can be dangerous, especially if they use a constructor that does something.

Quote
Also, no I haven't looked at the Code::Blocks page, it really didn't occur to me. THough I don't know what I would be looking for.

To make sure that you properly setup your compiler and environment -- which you didn't (but that doesn't explain your problem) ;)
Laurent Gomila - SFML developer

Frostbite

  • Newbie
  • *
  • Posts: 17
    • View Profile
Problem with program crashing as soon as activated
« Reply #5 on: February 24, 2010, 09:14:45 am »
Can I do that? Don't I need to declare it before I can use it in all of my functions?

Thanks for you patience... I can't help but feel really feel ignorant right now,

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem with program crashing as soon as activated
« Reply #6 on: February 24, 2010, 09:27:20 am »
Quote
Can I do that? Don't I need to declare it before I can use it in all of my functions?

You can declare it globally (although globals are bad -- but you'll learn how to avoid them), but you can just declare it empty and create it in main().

Code: [Select]
sf::RenderWindow Window;
...

int main()
{
    Window.Create(sf::VideoMode(650, 400, 32), "Avian");
    ...
}
Laurent Gomila - SFML developer

Frostbite

  • Newbie
  • *
  • Posts: 17
    • View Profile
Problem with program crashing as soon as activated
« Reply #7 on: February 24, 2010, 09:34:48 am »
Alright, I did that. and thanks, I actually had been wondering about that.
It still crashes, but I think im going to work on it more tomorrow, its twelve thirty at night here and I have to get up at six tomorrow. Thank you for your help. And if I can't solve it by this time on Wednesday I'll head back here.

Again, thanks a lot, its really great to have some help =)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem with program crashing as soon as activated
« Reply #8 on: February 24, 2010, 09:45:24 am »
If it still crashes, you can try removing every line of code that is not connected to the problem, and show me a minimal example that reproduces the problem.
Laurent Gomila - SFML developer

Frostbite

  • Newbie
  • *
  • Posts: 17
    • View Profile
Problem with program crashing as soon as activated
« Reply #9 on: February 25, 2010, 01:41:43 am »
ok, here we go, it still says not responding. Here is the condensed code I've compiled.

Code: [Select]

#include <SFML/Graphics.hpp>
using namespace std;

//------------------------------SF stuff------------------------------------------
    sf::RenderWindow Window;
//--------------------------End SF stuff------------------------------------------



int main(){
    Window.Create(sf::VideoMode(500, 300, 32), "Avian");
    int BattleOn = 4;
    while (BattleOn){

        }
}


It still crashed with a Window.Display()



-------------------edit---------------------------

and now its just my luck code::blocks is bugging out on me, I ran the exacutable in the snake game and took a look at the source code just before....
Now it gives me a window from mingw saying there is no disk in drive D, about a thousand times, or it says it uses an invalid compiler =(

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem with program crashing as soon as activated
« Reply #10 on: February 25, 2010, 08:17:23 am »
The event loop is missing. Without it, the window cannot handle its events and is kind of stuck (the exact effect depends on the OS).
Laurent Gomila - SFML developer

 

anything