Qt 5.5 and OpenGL: QVertexArrayObject::create() calls QPainter::drawimage()? - qt

I understand that for any of the Qt OpenGL convenience classes to correctly be initialized and used, they must be called with a valid current context. So, I designed my classes to be initialized from my overloaded QOpenGLWidget::initializeGL() function, in which the documentation states the context is created and made current (albeit without a framebuffer).
However, when initializeGL() attempts to initialize one of my subclasses MeshObject, specifically calling the function QOpenGLVertexArrayObject::create(), the program crashes with the message
Read access violation at 0x0
Going through with a debugger, note the call stack:
There are calls being made to QPainter::drawImage, which would surely fail as there is no framebuffer present.
But why is there a QPainter::drawImage call happening when I try to create a vertexArrayObject? Surely this function should have no involvement with painting to the screen.
ALthough the documentation also states that QOpenGLVertexArrayObjects will only work on some OpenGL ES 2.0 platforms, vbuffer.create() causes exactly the same scenario to occur, and I've already used QOpenGLVertexArrayObjects on this exact machine on a previous project with absolutely no problems.
Complete stack trace:
0 QPainter::drawImage Qt5Guid 0x58292a56
1 QPainter::drawImage Qt5Guid 0x5829203c
2 MeshState::initBuffers meshobject.cpp 71 0x2fb793
3 SceneObject::setupObjects sceneobject.cpp 18 0x2fa1eb
4 SceneObject::initialize sceneobject.cpp 12 0x2fa12f
5 OpenGLWidget::initializeGL openglwidget.cpp 34 0x2f8ecf
6 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x587a9859
7 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x587a86da
8 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x58770104
9 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x587a8850
10 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x5872548e
11 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x587235f5
12 QSortFilterProxyModel::mapToSource Qt5Cored 0x591b6b47
13 QSortFilterProxyModel::mapToSource Qt5Cored 0x591bf379
14 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x5877a3a3
15 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x5877a618
16 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x5876be41
17 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x5876c0bb
18 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x58779441
19 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x5877a62e
20 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x5876be41
21 QAbstractScrollArea::setHorizontalScrollBar Qt5Widgetsd 0x5876c0bb
22 main main.cpp 10 0x2f3419
23 WinMain qtmain_win.cpp 113 0x2fdcdd
24 __tmainCRTStartup crtexe.c 618 0x2fd0bf
25 WinMainCRTStartup crtexe.c 466 0x2fce7d
26 BaseThreadInitThunk KERNEL32 0x772e38f4
27 __RtlUserThreadStart ntdll 0x77865de3
28 _RtlUserThreadStart ntdll 0x77865dae

Related

VSCode showing two color decorators instead of one

I tried asking this on the VSCode subreddit and have had no replies so I'm hoping someone here will be able to help.
My VScode shows two color decorators instead of one, as normal.
Screenshot of the issue at hand:
I've tried disabling and re-enabling both the regular color decorator settings and the ones for Tailwind, and nothing has worked. I even enabled the setting manually in the JSON settings file and the issue persists.
I'm wondering if this could be another extension messing with this or if there is something I could try that someone else has found useful.
Here are the extensions I have installed as from the output of VSCode itself:
1 adpyke.codesnap
2 alefragnani.Bookmarks
3 apollographql.vscode-apollo
4 bradlc.vscode-tailwindcss
5 dsznajder.es7-react-js-snippets
6 eamodio.gitlens
7 esbenp.prettier-vscode
8 formulahendry.auto-close-tag
9 formulahendry.auto-rename-tag
10 glenn2223.live-sass
11 heybourn.headwind
12 marlosirapuan.nord-deep
13 miguelsolorio.fluent-icons
14 mikestead.dotenv
15 mkaufman.HTMLHint
16 ms-azuretools.vscode-docker
17 ms-python.python
18 ms-python.vscode-pylance
19 ms-toolsai.jupyter
20 ms-toolsai.jupyter-keymap
21 ms-toolsai.jupyter-renderers
22 ms-vsliveshare.vsliveshare
23 ms-vsliveshare.vsliveshare-audio
24 ms-vsliveshare.vsliveshare-pack
25 octref.vetur
26 PKief.material-icon-theme
27 PKief.material-product-icons
28 pomber.git-file-history
29 ritwickdey.LiveServer
30 Shan.code-settings-sync
31 streetsidesoftware.code-spell-checker
32 techer.open-in-browser
33 Tobermory.es6-string-html
34 usernamehw.errorlens
35 vscodevim.vim
36 Vue.volar
Thanks in advance!

Morans correlogram with only one point. What is wrong?

Im trying Moran's I and respective plot in r. But the plot has only one point. I have no idea of what is going wrong. The code is based on<
http://rstudio-pubs-static.s3.amazonaws.com/9688_a49c681fab974bbca889e3eae9fbb837.html>
my data called "coordenata"
resid x y
1 0.07785411 -53.20342 -22.66700
2 -0.28358702 -53.20389 -22.66864
3 -0.64011338 -53.21392 -22.68122
4 1.22071249 -53.21311 -22.72369
5 0.95734778 -53.28469 -22.75289
6 0.35345302 -53.25822 -22.74850
7 -0.68357738 -53.28344 -22.70694
8 -1.24596010 -53.32950 -22.72872
9 -0.19944162 -53.33669 -22.73561
10 0.67544909 -53.36756 -22.80767
11 0.64002961 -53.35947 -22.79958
12 0.04564233 -53.21889 -22.67419
13 0.01618436 -53.24522 -22.70144
14 -2.65436794 -53.23017 -22.69292
15 0.72096256 -53.25539 -22.69978
16 0.89656515 -53.28489 -22.72222
17 1.85358579 -53.33069 -22.79161
18 -0.03590077 -53.33200 -22.78336
19 0.32348975 -53.33494 -22.78586
20 2.06771402 -53.37781 -22.77869
21 -1.02190709 -53.30492 -22.77244
22 -2.02813250 -53.53917 -22.79856
23 -1.20702445 -53.53858 -22.79406
24 -1.24091732 -53.55272 -22.80536
25 -1.13491596 -53.56181 -22.82914
26 -0.82934613 -53.56422 -22.83417
27 1.23418758 -53.60017 -22.85531
28 -1.72808514 -53.65900 -22.97828
29 -0.02144049 -53.65908 -22.97497
30 0.49174568 -53.64597 -22.95439
31 -0.54408149 -53.64217 -22.91033
32 -0.37111342 -53.61447 -22.86269
33 -0.31121931 -53.27153 -22.70036
34 0.32419211 -53.30308 -22.72183
35 1.57980287 -53.33053 -22.72947
36 -1.91156060 -53.34633 -22.74722
37 -0.79036645 -53.23667 -22.68925
the code
coordinates(coordenata)<-c("x","y")
fit2<-correlog(coordenata$x,coordenata$y,coordenata$resid,increment=5,resamp=100,quiet=T)
plot(fit2)
Thanks in advance for any help!

Having issues with adding two positions of array

Question in regards to adding arrays. I have this code below:
B[row][col] = B[row+1][col+1] + B[row][col+1];
Let say row = 2, col = 3; I don't quite understand what happens how. We have the (=) assignment so I'm guessing would assign whatever is on the right but I don't know how to count it. In this example it come up to me to be: 13 on the right side but that doesn't make sense. I would assign 13 value to b[row][col] ??? In the tracing program showed as 2. I don't understand, please help!
I'm not entirely sure what it is you're asking but essentially you have a 2D array and the B[row][col] syntax is to access a specific "cell" within the 2D array. Think of it like a grid. So what you're doing with the assignment operator is taking the values in cells B[row+1][col+1] and B[row][col+1], adding them together, and assigning that resulting value to the cell B[row][col]. Does that make sense? Also it'll be good to make sure you don't get any index out of bounds exceptions doing this.
This does somewhat depend on the tool/language you are using, for instance matlab starts indexing arrays at 1 so the first element of an array a is a[1] while languages like C/Java start indexing at 0 so the first element of an array a is a[0].
Lets assume that indexing is done like in C/Java, then consider a multidimensional array B
12 13 14 11
41 17 23 22
18 10 20 38
81 17 32 61
Then with row = 2 and col = 3 you will have that B[row][col] as the element that sits on the third row (remembering indexing starts at 0, so B[2] is the third row) and fourth column, marked here between * signs.
12 13 14 11
41 17 23 22
18 10 20 *38*
81 17 32 61
As for changing a value in the multidimensional array, it is done by assigning a new value to the index of the old value.
B[row][col] = B[row+1][col+1] + B[row][col+1];
With row=1 and col=0 we get
B[1][0] = B[2][1] + B[1][1];
B[1][0] = 10 + 17;
B[0][0] = 27;
Or:
12 13 14 11 12 13 14 11
(41) 17 23 22 (27) 17 23 22
18 10 20 38 ==> 18 10 20 38
81 17 32 61 81 17 32 61

Multiple unions

I am trying to do unions on several lists (these are actually GRanges objects not integer lists but the priciple is the same), basically one big union.
x<-sort(sample(1:20, 9))
y<-sort(sample(10:30, 9))
z<-sort(sample(20:40, 9))
mylists<-c("x","y","z")
emptyList<-list()
sapply(mylists,FUN=function(x){emptyList<-union(emptyList,get(x))})
That is just returning the list contents.
I need the equivalent of
union(x,union(y,z))
[1] 2 3 5 6 7 10 13 15 20 14 19 21 24 27 28 29 26 31 36 39
but written in an extensible and non-"variable explicit" form
A not necessarily memory efficient paradigm that will work with GRanges is
Reduce(union, list(x, y, z))
The argument might also be a GRangesList(x, y, z) for appropriate values of x etc.
x<-sort(sample(1:20, 9))
y<-sort(sample(10:30, 9))
z<-sort(sample(20:40, 9))
Both of the below produce the same output
unique(c(x,y,z))
[1] 1 2 4 6 7 8 11 15 17 14 16 18 21 23 26 28 29 20 22 25 31 32 35
union(x,union(y,z))
[1] 1 2 4 6 7 8 11 15 17 14 16 18 21 23 26 28 29 20 22 25 31 32 35
unique(unlist(mget(mylists, globalenv())))
will do the trick. (Possibly changing the environment given in the call to mget, as required.)
I think it would be cleaner to separate the "dereference" part from the n-ary union part, e.g.
dereflist <- function(l) lapply(a,get)
nunion <- function(l) Reduce(union,l)
But if you look at how union works, you'll see that you could also do
nunion <- function(l) unique(do.call(c,l))
which is faster in all the cases I've tested (much faster for long lists).
-s
This can be done by using the reduce function in the purrr package.
purrr::reduce(list(x, y, z),union)
ok this works but I am curious why sapply seems to have its own scope
x<-sort(sample(1:20, 9))
y<-sort(sample(10:30, 9))
z<-sort(sample(20:40, 9))
mylists<-c("x","y","z")
emptyList<-vector()
for(f in mylists){emptyList<-union(emptyList,get(f))}

R sorts a vector on its own accord

df.sorted <- c("binned_walker1_1.grd", "binned_walker1_2.grd", "binned_walker1_3.grd",
"binned_walker1_4.grd", "binned_walker1_5.grd", "binned_walker1_6.grd",
"binned_walker2_1.grd", "binned_walker2_2.grd", "binned_walker3_1.grd",
"binned_walker3_2.grd", "binned_walker3_3.grd", "binned_walker3_4.grd",
"binned_walker3_5.grd", "binned_walker4_1.grd", "binned_walker4_2.grd",
"binned_walker4_3.grd", "binned_walker4_4.grd", "binned_walker4_5.grd",
"binned_walker5_1.grd", "binned_walker5_2.grd", "binned_walker5_3.grd",
"binned_walker5_4.grd", "binned_walker5_5.grd", "binned_walker5_6.grd",
"binned_walker6_1.grd", "binned_walker7_1.grd", "binned_walker7_2.grd",
"binned_walker7_3.grd", "binned_walker7_4.grd", "binned_walker7_5.grd",
"binned_walker8_1.grd", "binned_walker8_2.grd", "binned_walker9_1.grd",
"binned_walker9_2.grd", "binned_walker9_3.grd", "binned_walker9_4.grd",
"binned_walker10_1.grd", "binned_walker10_2.grd", "binned_walker10_3.grd")
One would expect that order of this vector would be 1:length(df.sorted), but that appears not to be the case. It looks like R internally sorts the vector according to its logic but tries really hard to display it the way it was created (and is seen in the output).
order(df.sorted)
[1] 37 38 39 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
[26] 23 24 25 26 27 28 29 30 31 32 33 34 35 36
Is there a way to "reset" the ordering to 1:length(df.sorted)? That way, ordering, and the output of the vector would be in sync.
Use the mixedsort (or) mixedorder functions in package gtools:
require(gtools)
mixedorder(df.sorted)
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
[28] 28 29 30 31 32 33 34 35 36 37 38 39
construct it as an ordered factor:
> df.new <- ordered(df.sorted,levels=df.sorted)
> order(df.new)
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
EDIT :
After #DWins comment, I want to add that it is even not nessecary to make it an ordered factor, just a factor is enough if you give the right order of levels :
> df.new2 <- factor(df.sorted,levels=df.sorted)
> order(df.new)
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
The difference will be noticeable when you use those factors in a regression analysis, they can be treated differently. The advantage of ordered factors is that they let you use comparison operators as < and >. This makes life sometimes a lot easier.
> df.new2[5] < df.new2[10]
[1] NA
Warning message:
In Ops.factor(df.new[5], df.new[10]) : < not meaningful for factors
> df.new[5] < df.new[10]
[1] TRUE
Isn't this simply the same thing you get with all lexicographic shorts (as e.g. ls on directories) where walker10_foo sorts higher than walker1_foo?
The easiest way around, in my book, is to use a consistent number of digits, i.e. I would change to binned_walker01_1.grd and so on inserting a 0 for the one-digit counts.
In response to Dwin's comment on Dirk's answer: the data are always putty in your hands. "This is R. There is no if. Only how." -- Simon Blomberg
You can add 0 like so:
df.sorted <- gsub("(walker)([[:digit:]]{1}_)", "\\10\\2", df.sorted)
If you needed to add 00, you do it like this:
df.sorted <- gsub("(walker)([[:digit:]]{1}_)", "\\10\\2", df.sorted)
df.sorted <- gsub("(walker)([[:digit:]]{2}_)", "\\10\\2", df.sorted)
...and so on.

Resources