1

While trying to understand the pbPlots library i wrote a piece of code:

#include "pbPlots.hpp"
#include "supportLib.hpp"
#include <vector>
#include<iostream>
using namespace std;

void print(std::vector<double> const &input)
{
    for (int i = 0; i < input.size(); i++) {
        std::cout << input.at(i) << ' ';
    }
}

int main(){
RGBABitmapImageReference *imageRef = CreateRGBABitmapImageReference();

vector<double> x = {1,2,3,4,5,6,7,8,9,10};
vector<double> y = {1,4,9,16,25,36,49,64,81,100};

/*for(int i = 1; i <= 10; i++){
    x.push_back(i);
    y.push_back(i*i);
}*/

//print(x);
//print(y);
/*int a;
cin >> a;*/
DrawScatterPlot(imageRef, 600, 400, &x,&y);

vector<double> *pngData = ConvertToPNG(imageRef->image);
WriteToFile(pngData, "plot.png");
DeleteImage(imageRef->image);
}

With the code above I wanted to create two vectors "x" and "y", and then plot them in a graph and export it to png.

At first I used the for loop to put values into the vectors automatically and then I built the programme with no errors given, but when i tried to run the a.exe I get the error below: Error when I run the a.exe file after building the programme

I then thought it could be related to the fact that i used a for loop so I inputed the values mannualy and built the programme again, and it built with no errors once again, but then when I tried to run a.exe again it gave exactly the same error it did before using the for loop.

Since I am new to pbPlots I wanted to know what I am doing wrong.

Im running Windows 10.

Rui Coito
  • 379
  • 1
  • 3
  • 6
  • 1
    4294967295 is 32^2 -1. My guess is that someone used a loop with `size()-1` on an empty vector – 463035818_is_not_an_ai May 31 '21 at 09:30
  • And is that something I did wrong or is that a problem of pbPlots ? @463035818_is_not_a_number – Rui Coito May 31 '21 at 09:35
  • 1
    returning a pointer to a vector is rather odd, I would not be surprised if it is in the lib. I dont see the wrap around in your code – 463035818_is_not_an_ai May 31 '21 at 09:38
  • Well, not to be too critical, going by the source code at the [github page](https://github.com/InductiveComputerScience/pbPlots/blob/master/Cpp/pbPlots.cpp), the author is either not aware of references, move constructors and/or move assignment operators, or what an optimizing C++ compiler in the modern era can perform. Everything seems to be pointers and `new`. But given that, you need to take the code and make sure you're building it yourself into your app, and not take something that was built already. – PaulMcKenzie May 31 '21 at 10:44
  • Did you use a pre-built lib or include the files in your project? If you included the source files in your protect then break into the debugger when you get the exception report and have a look. Use the Stack Frame window to unwind the stack and inspect the local variables as you go up the stack. – Richard Critten May 31 '21 at 10:45
  • @RuiCoito, I tried your code on my Ubuntu box and it works. 1) Which compiler did you use and 2) did you get more error information? – Martin Johansen Dec 29 '21 at 10:33
  • I tried your code with Visual Studio 2022 on Windows 10. I tried with different C++ standards, 32- and 64-bit, different versions of pbPlots and I tried with and without the commented code in your example. I was not able to reproduce your problem. I would be more than happy to identify the problem for you, but I need to know more: Which compiler, what settings? pbPlots aims to work almost everywhere. – Martin Johansen Mar 23 '22 at 12:55

1 Answers1

0

This was a bug in pbPlots when built using MinGW on Windows. It got fixed in v0.1.9.1 of the library.

Martin Johansen
  • 131
  • 1
  • 4