[gecode-users] Access Violation when temporary BoolVarAgs looses scope.

Christian Schulte cschulte at kth.se
Thu Jun 27 15:23:34 CEST 2013


Hi Uwe,

No, what you do is fine. This must be a bug in Gecode or an issue related to
DLLs in Windows (more likely). The 16 versus 17 is okay because up 16 the
temporary array is allocated on the stack and otherwise on the heap. So heap
allocation is the problem apparently.

I just tried it on my Windows machine x64 with MSVC 2012 and it works fine.

Now I have a strange question for you: does your project use several DLLs? I
have an idea which has to do with a restriction in Windows: memory allocated
by a function in one DLL must also be deallocated by a function from the
same DLL. When some functions are inlined and others are not, then they
might end up in different DLLs and a problem might occur (the program will
crash).

Did you compile in debug or release mode?

Best
Christian

--
Christian Schulte, Professor of Computer Science, KTH,
www.ict.kth.se/~cschulte/



-----Original Message-----
From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Uwe Nowak
Sent: Thursday, June 27, 2013 12:57 PM
To: users at gecode.org
Subject: [gecode-users] Access Violation when temporary BoolVarAgs looses
scope.

Hello!

I am getting an access violation creating a custom Space and boiled it down
to the following minimal example.
When the tmp array is destroyed (as it gets out of scope) I get an access
violation.
Visual Studio 10, 32bit (on a 64 bit machine)

Did I missunderstand the concept of temporary variables? If all variables
are instance variables, everything works fine.
Interesting enough, it also works if tmp  has a length less or equal to 16.


class DummySpace : public Gecode::Space {
public:
  DummySpace(bool share, DummySpace& other)  : Space(share, other) { }

  DummySpace() { 
    {
      Gecode::BoolVarArgs tmp(*this, 17, 0, 1);
      for(int j = 0; j<tmp.size(); ++j) rel(*this, tmp[j] == 1);
    } //tmp gets out of scope
    std::cout << "Never executed!" << std::endl;
  }

  DummySpace* copy(bool share) {
    return new DummySpace(share, *this);
  }
};


Thank you for your support,
Uwe


_______________________________________________
Gecode users mailing list
users at gecode.org
https://www.gecode.org/mailman/listinfo/gecode-users




More information about the users mailing list