What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread Sean Campbell via Digitalmars-d-learn
I cannot figure out what is wrong with this code and why i keep 
getting object.error access violation. the code is simple 
tutorial code for SDL and OpenGL what am i doing wrong (the 
access violation seems to be with glGenBuffers)

The Code

import std.stdio;
import derelict.opengl3.gl3;
import derelict.sdl2.sdl;

float vertices[] = [
0.0f,  0.5f, // Vertex 1 (X, Y)
0.5f, -0.5f, // Vertex 2 (X, Y)
-0.5f, -0.5f  // Vertex 3 (X, Y)
];

int main(string args[]){
DerelictSDL2.load();
DerelictGL3.load();
SDL_Init(SDL_INIT_EVERYTHING);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 
SDL_GL_CONTEXT_PROFILE_CORE);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,2 );
	SDL_Window* window = SDL_CreateWindow(OpenGL, 100, 100, 800, 
600, SDL_WINDOW_OPENGL);

SDL_GLContext context = SDL_GL_CreateContext(window);
SDL_Event windowEvent;
GLuint vbo;
glGenBuffers(1, vbo); // Generate 1 buffer
glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (vertices[0]).sizeof * 
vertices.length, vertices.ptr, GL_STATIC_DRAW);

while (true)
{
if (SDL_PollEvent(windowEvent))
{
if (windowEvent.type == SDL_QUIT){
return 0;
			}else if (windowEvent.type == SDL_KEYUP  
windowEvent.key.keysym.sym == SDLK_ESCAPE){

return 0;
}
SDL_GL_SwapWindow(window);
}
}
return 0;
}


Re: What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread Misu via Digitalmars-d-learn
Can you try to add DerelictGL3.reload(); after 
SDL_GL_CreateContext ?


Re: What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread bearophile via Digitalmars-d-learn

Sean Campbell:

I cannot figure out what is wrong with this code and why i keep 
getting object.error access violation. the code is simple 
tutorial code for SDL and OpenGL what am i doing wrong (the 
access violation seems to be with glGenBuffers)


I don't know where your problem is, but you can start helping 
yourself with more tidy code (because this makes it more easy to 
fix) and adding some asserts on the pointers.




float vertices[] = [


Better to use the D syntax.



int main(string args[]){
DerelictSDL2.load();
DerelictGL3.load();
SDL_Init(SDL_INIT_EVERYTHING);


Better to add a space before the { and some blank lines to 
separate logically distinct pieces of your code.
Also, your main perhaps could be void (and use just empty returns 
inside it).



	SDL_Window* window = SDL_CreateWindow(OpenGL, 100, 100, 800, 
600, SDL_WINDOW_OPENGL);


Perhaps it's better to use auto here.


	glBufferData(GL_ARRAY_BUFFER, (vertices[0]).sizeof * 
vertices.length, vertices.ptr, GL_STATIC_DRAW);


Better to define a little function that computes the bytes of an 
array, and call it here, it's less bug-prone.


As a first step you can assert that all the pointers that should 
not be null in your program are not null. And then run a debugger.


Bye,
bearophile


transposed problem

2014-07-04 Thread bearophile via Digitalmars-d-learn

Is this another bug in std.range.transposed?


void main() {
import std.stdio, std.algorithm, std.range;
auto M = [[[1, 2]], [[3, 4]]];
M.filter!(r = r.dup.transposed.walkLength).writeln;
M.filter!(r = r.transposed.walkLength).writeln;
}


Output with the latest dmd:

[[[1, 2]], [[3, 4]]]
[[[]], [[]]]


Bye,
bearophile


Re: What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread Sean Campbell via Digitalmars-d-learn

On Friday, 4 July 2014 at 08:02:59 UTC, Misu wrote:
Can you try to add DerelictGL3.reload(); after 
SDL_GL_CreateContext ?


yes this solved the problem. however why? is it a problem with 
the SDL binding?


Re: What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread safety0ff via Digitalmars-d-learn

On Friday, 4 July 2014 at 09:39:49 UTC, Sean Campbell wrote:

On Friday, 4 July 2014 at 08:02:59 UTC, Misu wrote:
Can you try to add DerelictGL3.reload(); after 
SDL_GL_CreateContext ?


yes this solved the problem. however why? is it a problem with 
the SDL binding?


No.
https://github.com/DerelictOrg/DerelictGL3/blob/master/README.md


Re: What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread Mike Parker via Digitalmars-d-learn

On 7/4/2014 6:39 PM, Sean Campbell wrote:

On Friday, 4 July 2014 at 08:02:59 UTC, Misu wrote:

Can you try to add DerelictGL3.reload(); after SDL_GL_CreateContext ?


yes this solved the problem. however why? is it a problem with the SDL
binding?


OpenGL on Windows requires a context be created before attempting to 
load any extensions or any later versions of OpenGL beyond 1.1. Although 
this is not an issue on other platforms, the Derelict binding makes it a 
requirement for consistency. DerelictGL3.load loads the DLL into memory 
along with the 1.0  1.1 function addresses. You can call that at any 
time, before or after creating a context. If you do not call 
DerelictGL3.reload, you will never load the extensions and 1.2+ 
functions. If you attempt to call it before creating a context, Derelict 
will throw an exception.


---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com



Re: transposed problem

2014-07-04 Thread bearophile via Digitalmars-d-learn

https://issues.dlang.org/show_bug.cgi?id=13041

Bye,
bearophile


recursive definition error

2014-07-04 Thread Frustrated via Digitalmars-d-learn

After upgrading to latest dmd, I get the follow error on the code

template Array(T) { alias Array = std.container.Array!T; }

Error: Array!(iDataBlock).Array recursive alias declaration

I don't see anything recursive about it... and the code worked 
before. Any ideas?






Re: recursive definition error

2014-07-04 Thread bearophile via Digitalmars-d-learn

Frustrated:

After upgrading to latest dmd, I get the follow error on the 
code


template Array(T) { alias Array = std.container.Array!T; }


Try to use a different name inside the template, like Vector.

Bye,
bearophile


Re: recursive definition error

2014-07-04 Thread Frustrated via Digitalmars-d-learn

On Friday, 4 July 2014 at 15:10:14 UTC, bearophile wrote:

Frustrated:

After upgrading to latest dmd, I get the follow error on the 
code


template Array(T) { alias Array = std.container.Array!T; }


Try to use a different name inside the template, like Vector.

Bye,
bearophile


Huh?

The template is simply wrapping std.container.Array so I can 
later on use change it to a different array without breaking code 
that uses it. As I said, it worked fine before without this 
recursion problem.


Since there is no recursion going on there, it shouldn't be a 
problem. This seems like a bug/regression.


An indirection does not help.



Re: recursive definition error

2014-07-04 Thread via Digitalmars-d-learn

On Friday, 4 July 2014 at 15:07:00 UTC, Frustrated wrote:
After upgrading to latest dmd, I get the follow error on the 
code


template Array(T) { alias Array = std.container.Array!T; }

Error: Array!(iDataBlock).Array recursive alias declaration

I don't see anything recursive about it... and the code worked 
before. Any ideas?


Which version of DMD exactly? This works in DMD git.


Re: recursive definition error

2014-07-04 Thread bearophile via Digitalmars-d-learn

Frustrated:

Since there is no recursion going on there, it shouldn't be a 
problem.


Yes, sorry.

In dmd 2.066 this too could work:

alias Array(T) = std.container.Array!T;

Bye,
bearophile


Re: recursive definition error

2014-07-04 Thread Frustrated via Digitalmars-d-learn

On Friday, 4 July 2014 at 15:37:52 UTC, Marc Schütz wrote:

On Friday, 4 July 2014 at 15:07:00 UTC, Frustrated wrote:
After upgrading to latest dmd, I get the follow error on the 
code


template Array(T) { alias Array = std.container.Array!T; }

Error: Array!(iDataBlock).Array recursive alias declaration

I don't see anything recursive about it... and the code worked 
before. Any ideas?


Which version of DMD exactly? This works in DMD git.


I don't remember what I was using before, I think 2.064. I just 
upgraded to the latest 2.065.2 today and tried to compile some 
old code and got all these errors. The code was working fine 
before. Obviously I could have done something that I forgot but 
the errors are saying the templates are recursive as if the 
method doesn't work, yet it worked fine before.




Re: recursive definition error

2014-07-04 Thread Frustrated via Digitalmars-d-learn

On Friday, 4 July 2014 at 15:42:36 UTC, bearophile wrote:

Frustrated:

Since there is no recursion going on there, it shouldn't be a 
problem.


Yes, sorry.

In dmd 2.066 this too could work:

alias Array(T) = std.container.Array!T;

Bye,
bearophile



That just gives more errors.

I'm not using 2.066 though...

I will revert back to the dmd version I was using when it 
worked... Hopefully someone can make sure this is not a 
regression in the mean time... (seems like it is and I don't want 
to get bit again later on when I upgrade)


Re: recursive definition error

2014-07-04 Thread Stanislav Blinov via Digitalmars-d-learn

On Friday, 4 July 2014 at 16:28:48 UTC, Frustrated wrote:

On Friday, 4 July 2014 at 15:42:36 UTC, bearophile wrote:

Frustrated:



I'm not using 2.066 though...

I will revert back to the dmd version I was using when it 
worked... Hopefully someone can make sure this is not a 
regression in the mean time... (seems like it is and I don't 
want to get bit again later on when I upgrade)


That template and its instantiation work fine for me on both 
2.065 and 2.066b1.


Re: recursive definition error

2014-07-04 Thread Frustrated via Digitalmars-d-learn

On Friday, 4 July 2014 at 16:31:28 UTC, Stanislav Blinov wrote:

On Friday, 4 July 2014 at 16:28:48 UTC, Frustrated wrote:

On Friday, 4 July 2014 at 15:42:36 UTC, bearophile wrote:

Frustrated:



I'm not using 2.066 though...

I will revert back to the dmd version I was using when it 
worked... Hopefully someone can make sure this is not a 
regression in the mean time... (seems like it is and I don't 
want to get bit again later on when I upgrade)


That template and its instantiation work fine for me on both 
2.065 and 2.066b1.


Ok, I do not know where this error creeped in at. I do know at 
one point the code was working fine without any changes I 
believe. (it's possible though I messed something up)


The recursive error seems to be the wrong issue. Trying to 
diagnose what the problem is now.


Re: recursive definition error

2014-07-04 Thread Frustrated via Digitalmars-d-learn

On Friday, 4 July 2014 at 20:25:28 UTC, Frustrated wrote:

On Friday, 4 July 2014 at 16:31:28 UTC, Stanislav Blinov wrote:

On Friday, 4 July 2014 at 16:28:48 UTC, Frustrated wrote:

On Friday, 4 July 2014 at 15:42:36 UTC, bearophile wrote:

Frustrated:



I'm not using 2.066 though...

I will revert back to the dmd version I was using when it 
worked... Hopefully someone can make sure this is not a 
regression in the mean time... (seems like it is and I don't 
want to get bit again later on when I upgrade)


That template and its instantiation work fine for me on both 
2.065 and 2.066b1.


Ok, I do not know where this error creeped in at. I do know at 
one point the code was working fine without any changes I 
believe. (it's possible though I messed something up)


The recursive error seems to be the wrong issue. Trying to 
diagnose what the problem is now.


This must be some weird issue with Array or a change in what 
imports does.


e.g.,

if I do

struct apple(T) { }

template Array(T) { alias apple!T Array; }

Then the code works(except I no longer can use array as an array 
but I do not get any recursive issues.


The compiler I was using when it worked might have been pre 
2.064... Or possibly something else is going on that breaks the 
code.


Best I can tell is that the compiler is getting confused between 
std.container.Array and my Array.


Problem Linking Phobos git master

2014-07-04 Thread Nordlöw
On Ubuntu 14.04 my git master build script for phobos now fails 
as below.


Why? Help please.

/usr/bin/ld points to /usr/bin/ld.bfd on my system

Terminal echo and error message follows:

../dmd/src/dmd 
-I/home/per/opt/x86_64-unknown-linux-gnu/dmd/include/d2 -shared 
-debuglib= -defaultlib= 
-ofgenerated/linux/release/64/libphobos2.so.0.66.0 
-L-soname=libphobos2.so.0.66 
../druntime/lib/libdruntime-linux64so.a -L-ldl 
-Lgenerated/linux/release/64/libcurl_stub.so std/algorithm.d 
std/array.d std/ascii.d std/base64.d std/bigint.d std/bitmanip.d 
std/compiler.d std/complex.d std/concurrency.d std/conv.d 
std/cstream.d std/csv.d std/datetime.d std/demangle.d 
std/encoding.d std/exception.d std/file.d std/format.d 
std/functional.d std/getopt.d std/json.d std/math.d 
std/mathspecial.d std/mmfile.d std/numeric.d std/outbuffer.d 
std/parallelism.d std/path.d std/process.d std/random.d 
std/range.d std/regex.d std/signals.d std/socket.d 
std/socketstream.d std/stdint.d std/stdio.d std/stdiobase.d 
std/stream.d std/string.d std/syserror.d std/system.d 
std/traits.d std/typecons.d std/typetuple.d std/uni.d std/uri.d 
std/utf.d std/uuid.d std/variant.d std/xml.d std/zip.d std/zlib.d 
std/c/linux/linux.d std/c/linux/socket.d etc/c/curl.d 
etc/c/sqlite3.d etc/c/zlib.d std/c/fenv.d std/c/locale.d 
std/c/math.d std/c/process.d std/c/stdarg.d std/c/stddef.d 
std/c/stdio.d std/c/stdlib.d std/c/string.d std/c/time.d 
std/c/wcharh.d std/internal/digest/sha_SSSE3.d 
std/internal/math/biguintcore.d std/internal/math/biguintnoasm.d 
std/internal/math/biguintx86.d std/internal/math/gammafunction.d 
std/internal/math/errorfunction.d std/internal/processinit.d 
std/internal/unicode_tables.d std/internal/scopebuffer.d 
std/internal/unicode_comp.d std/internal/unicode_decomp.d 
std/internal/unicode_grapheme.d std/internal/unicode_norm.d 
std/net/isemail.d std/net/curl.d std/digest/digest.d 
std/digest/crc.d std/digest/md.d std/digest/ripemd.d 
std/digest/sha.d std/container/package.d std/container/array.d 
std/container/binaryheap.d std/container/dlist.d 
std/container/rbtree.d std/container/slist.d std/container/util.d 
generated/linux/release/64/etc/c/zlib/adler32.o 
generated/linux/release/64/etc/c/zlib/compress.o 
generated/linux/release/64/etc/c/zlib/crc32.o 
generated/linux/release/64/etc/c/zlib/deflate.o 
generated/linux/release/64/etc/c/zlib/gzclose.o 
generated/linux/release/64/etc/c/zlib/gzlib.o 
generated/linux/release/64/etc/c/zlib/gzread.o 
generated/linux/release/64/etc/c/zlib/gzwrite.o 
generated/linux/release/64/etc/c/zlib/infback.o 
generated/linux/release/64/etc/c/zlib/inffast.o 
generated/linux/release/64/etc/c/zlib/inflate.o 
generated/linux/release/64/etc/c/zlib/inftrees.o 
generated/linux/release/64/etc/c/zlib/trees.o 
generated/linux/release/64/etc/c/zlib/uncompr.o 
generated/linux/release/64/etc/c/zlib/zutil.o
std/mmfile.d(344): Deprecation: alias 
core.sys.posix.sys.mman.MAP_ANON is deprecated - Please use 
core.sys.linux.sys.mman for non-POSIX extensions
std/mmfile.d(344): Deprecation: alias 
core.sys.posix.sys.mman.MAP_ANON is deprecated - Please use 
core.sys.linux.sys.mman for non-POSIX extensions
/usr/bin/ld: generated/linux/release/64/libphobos2.so.0.66.o: 
relocation R_X86_64_32 against 
`_D6object8TypeInfo8postblitMxFPvZv' can not be used when making 
a shared object; recompile with -fPIC
generated/linux/release/64/libphobos2.so.0.66.o: error adding 
symbols: Bad value

collect2: error: ld returned 1 exit status
--- errorlevel 1


Re: Problem Linking Phobos git master

2014-07-04 Thread Kapps via Digitalmars-d-learn
Possibly something related to: 
https://github.com/D-Programming-Language/dmd/pull/3715


Have you tried updating to git master today?