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

Author Topic: Program attempting to delete itself  (Read 2487 times)

0 Members and 1 Guest are viewing this topic.

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Program attempting to delete itself
« on: May 13, 2015, 12:14:35 pm »
I've made this program and it runs and compiles fine, but it I change anything and re-compile and run it, my antivirus either stops my exe for trying to delete itself, or it stops Id.exe. Does anyone have any idea why this is happening? As I have no idea what is causing this, I'll give my full code, it isn't that long. As I'm using RAII I thought it might be to do with that and there are some people who are amazing at it on here, but I don't know and it might be to do with my sfml code.
main.cpp:
Code: [Select]
#include <SFML/Graphics.hpp>

#include "block.hpp"

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    window.setFramerateLimit(60);
    sf::Image tileImage;
    std::shared_ptr<sf::Texture> bodyTexture;
    std::array<std::shared_ptr<sf::Texture>,24> pistonTextures;
    std::array<std::shared_ptr<sf::Texture>,24> leftConnectorTextures;
    std::array<std::shared_ptr<sf::Texture>,24> rightConnectorTextures;
    tileImage.loadFromFile("tilesheet.png");
    bodyTexture.reset(new sf::Texture);
    for(int i (0); i < 24; i = i + 1)
    {
        pistonTextures[i].reset(new sf::Texture);
        leftConnectorTextures[i].reset(new sf::Texture);
        rightConnectorTextures[i].reset(new sf::Texture);
    }
    bodyTexture->loadFromImage(tileImage,sf::IntRect(0,0,32,32));
    for(int i (0); i < 24; i = i + 1)
    {
        pistonTextures[i]->loadFromImage(tileImage,sf::IntRect(66+(9*i),0,8,26));
        leftConnectorTextures[i]->loadFromImage(tileImage,sf::IntRect(66+(9*i),27,8,12));
        rightConnectorTextures[i]->loadFromImage(tileImage,sf::IntRect(66+(9*i),40,8,12));
    }
    block Block(bodyTexture,pistonTextures,leftConnectorTextures,rightConnectorTextures,0,0);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        Block.draw(window);
        window.display();
    }
    return 0;
}

block.hpp:
Code: [Select]
#ifndef BLOCK_HPP_INCLUDED
#define BLOCK_HPP_INCLUDED

#include <array>
#include <memory>

class block{
private:
    std::shared_ptr<sf::Texture> bodyTexture;
    std::array<std::shared_ptr<sf::Texture>,24> pistonTextures;
    std::array<std::shared_ptr<sf::Texture>,24> leftConnectorTextures;
    std::array<std::shared_ptr<sf::Texture>,24> rightConnectorTextures;
    std::array<sf::Sprite,16> sprites;
    int xpos, ypos, pistonFrame, leftConnectorFrame, rightConnectorFrame;
    static const int pistonLimit = 24;
    static const int leftConnectorLimit = 24;
    static const int rightConnectorLimit = 24;
    bool changePiston, changeLeftCon, changeRightCon, upLinked, downLinked, leftLinked, rightLinked;
public:
    block(std::shared_ptr<sf::Texture> BodyTexture,std::array<std::shared_ptr<sf::Texture>,24> PistonTextures,std::array<std::shared_ptr<sf::Texture>,24> LeftConnectorTextures,std::array<std::shared_ptr<sf::Texture>,24> RightConnectorTextures,int xPos, int yPos);
    void draw(sf::RenderWindow & window);
};

#endif // BLOCK_HPP_INCLUDED


block.cpp:
Code: [Select]
#include <SFML/Graphics.hpp>

#include "block.hpp"

block::block(std::shared_ptr<sf::Texture> BodyTexture,std::array<std::shared_ptr<sf::Texture>,24> PistonTextures,std::array<std::shared_ptr<sf::Texture>,24> LeftConnectorTextures,std::array<std::shared_ptr<sf::Texture>,24> RightConnectorTextures,int xPos, int yPos)
{
    xpos = xPos;
    ypos = yPos;

    pistonFrame =
    leftConnectorFrame =
    rightConnectorFrame =
    changePiston =
    changeLeftCon =
    changeRightCon =
    upLinked =
    downLinked =
    rightLinked =
    leftLinked =
    0;

    bodyTexture = BodyTexture;

    for(int i (0); i < 24; i = i + 1)
    {
        pistonTextures[i] = PistonTextures[i];
        rightConnectorTextures[i] = RightConnectorTextures[i];
        leftConnectorTextures[i] = LeftConnectorTextures[i];
    }

    for(int i (0); i < 16; i = i + 4)
    {
        sprites[i].setTexture(*bodyTexture);
        sprites[i+1].setTexture(*(pistonTextures[0]));
        sprites[i+2].setTexture(*(leftConnectorTextures[0]));
        sprites[i+3].setTexture(*(rightConnectorTextures[0]));
    }

    for(int i (0); i < 16; i = i + 4)
    {
        sprites[0].setPosition(xpos,ypos);
        sprites[i+1].setPosition(xpos+28,ypos);
        sprites[i+2].setPosition(xpos+14,ypos);
        sprites[i+3].setPosition(xpos,ypos+22);
        sprites[i].setRotation(90*(i/4));
        sprites[i+1].setRotation(90*(i/4));
        sprites[i+2].setRotation(90*(i/4));
        sprites[i+3].setRotation(270 + (90*(i/4)));
    }

    sprites[4].setPosition(xpos+64,ypos);
    sprites[5].setPosition(xpos+64,ypos+28);
    sprites[6].setPosition(xpos+64,ypos+14);
    sprites[7].setPosition(xpos+42,ypos);
    sprites[8].setPosition(xpos+64,ypos+64);
    sprites[9].setPosition(xpos+36,ypos+64);
    sprites[10].setPosition(xpos+50,ypos+64);
    sprites[11].setPosition(xpos+64,ypos+42);
    sprites[12].setPosition(xpos,ypos+64);
    sprites[13].setPosition(xpos,ypos+36);
    sprites[14].setPosition(xpos,ypos+50);
    sprites[15].setPosition(xpos+22,ypos+64);

}

void block::draw(sf::RenderWindow & window)
{
    window.draw(sprites[0]);
    window.draw(sprites[4]);
    window.draw(sprites[8]);
    window.draw(sprites[12]);
    window.draw(sprites[1]);
    window.draw(sprites[5]);
    window.draw(sprites[9]);
    window.draw(sprites[13]);
    window.draw(sprites[2]);
    window.draw(sprites[6]);
    window.draw(sprites[10]);
    window.draw(sprites[14]);
    window.draw(sprites[3]);
    window.draw(sprites[7]);
    window.draw(sprites[11]);
    window.draw(sprites[15]);
}


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
AW: Program attempting to delete itself
« Reply #1 on: May 13, 2015, 01:35:33 pm »
It is generally advised to exclude your build directory from your AV, because some detect false-positives.

I even would go as far as to exclude any directory which gets searched for parsing or similar, after all you don't want the AV slow down your IDE. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Program attempting to delete itself
« Reply #2 on: May 13, 2015, 01:37:03 pm »
I know they do sometimes produce false positives, it's just that whenever I googled about Id.exe, it's usually because of an external library and I thought the program attempting to delete itself might be because of something I'd done wrong with RAII.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
AW: Program attempting to delete itself
« Reply #3 on: May 13, 2015, 01:44:06 pm »
Programs don't and actually can't delete themselves.

Since I didn't really understand what exactly is happening, here are some general statements.

ld.exe is the linker, it's used to link your application's object files as well as link to other libraries.

When rebuilding the application the old one gets first removed ol(or overwritten).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Program attempting to delete itself
« Reply #4 on: May 13, 2015, 01:54:00 pm »
Okay, thank you for the clarification. I was just worried partially because it's the first time I've used lots of std::shared_ptrs, and partially because I'm programming on a new laptop at the moment and I wanted to be sure I wasn't breaking it.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: AW: Program attempting to delete itself
« Reply #5 on: May 13, 2015, 07:56:13 pm »
Programs don't and actually can't delete themselves.
Ok, I'll be pedantic and bite.
A program most certainly can delete itself. It can locate and delete (unlink()) its own executable file and linked libraries from the underlying filesystem and subsequently exit() (thus removing itself from memory as well). I'd call that "deleting itself"  ;)

Yes, yes, I know that's not what you mean (I think), but I just had to comment anyway... This is probably just (yet another) example of crappy antivirus (nay, snakeoil) messing up and complaining about stuff it should just keep its nose out of.
« Last Edit: May 13, 2015, 08:33:42 pm by Jesper Juhl »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
AW: Program attempting to delete itself
« Reply #6 on: May 13, 2015, 08:45:33 pm »
...on Windows





...without doing some anarchic stuff




;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Program attempting to delete itself
« Reply #7 on: May 13, 2015, 08:51:45 pm »
Challenge accepted.  ;D
I'll write you a program that "deletes itself" on multiple platforms (including Windows; and I'll try to hold the anachronisms to a minimum). ;)
« Last Edit: May 13, 2015, 08:55:22 pm by Jesper Juhl »

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Program attempting to delete itself
« Reply #8 on: May 13, 2015, 09:11:27 pm »
Challenge accepted.  ;D
I'll write you a program that "deletes itself" on multiple platforms (including Windows; and I'll try to hold the anachronisms to a minimum). ;)
Could you please post it publicly (didn't know if you intended to post it or message it to eXpl0it3r), I'd really like to see how it works.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
AW: Program attempting to delete itself
« Reply #9 on: May 13, 2015, 09:12:21 pm »
Actually the reason I was confused that it can't delete itself, was because I was thinking you can't delete it from the same process on Windows. :D
But you probably know more than I do.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Program attempting to delete itself
« Reply #10 on: May 13, 2015, 09:17:28 pm »
Won't have time to write it until tomorrow evening, but I'll post it here.