Imgui: is this library not for beginners? Still having error I don't understand

Created on 25 Jun 2017  Â·  19Comments  Â·  Source: ocornut/imgui

I've been trying for three days to figure out how to get any of the examples to work at all, but I'm just constantly getting compiler errors and crashes

I don't understand what's going wrong here because I thought I was following what little documentation there is perfectly

clearly there's some sort of insider information that is just assumed to already be known here that I just don't know, because everything seems to assume that I already know something I clearly don't

what the hell am I doing wrong? I finally got one of the examples to compile, but it immediately crashes at " ImFontAtlas::GetTexDataAsAlpha8(unsigned char* out_pixels, int out_width, int* out_height, int* out_bytes_per_pixel)" with an "Unhandled exception at 0x001E20B6 in Test2.exe: 0xC0000005: Access violation reading location 0x00000004" error

alright I'll write out the stack here and see if that helps more:
main -> ImGui_ImplSdl_NewFrame -> ImGui_ImplSdl_CreateDeviceObjects -> ImFontAtlas::GetTexDataAsAlpha8 on the line checking if the TexPixelsAlpha8 is null

so it seems to be getting an access violation when trying to access the struct's member here, but I don't know how to find out why

maybe I've compiled with the wrong version of c++?

Most helpful comment

@mfriend,
We're trying to help you but it's difficult since the provided information is a little confusing and suggests that you aren't yet very familiar with c++. If you provided a callstack and compiled in debug mode with assert enabled (which would be by default in a Debug project in visual studio), we'd have more data to guide you.
The problem is unlikely to be imgui's fault because this code has been well exercised in the past and your setup is fairly standard.

All 19 comments

Post your whole project perhaps? I don't see how it could crash at that place, unless some bad pointers are involved.

do you mean post the link to a github containing the project like this? https://github.com/mfriendc/test2

all the project is is just a verbatim copy of sdl_opengl3_example with fixed includes

I'm not understanding what I could have done to break it, to be honest

What are you using to compile? Project file (if you are using VS) or makefile would be useful as well.

It's mostly C/C++ languages and the associated ecosystems of compilers, build systems and IDE are harsh for beginners.

There are many ways something can go wrong. Many of those things may be obvious or trivial to a more experienced programmer, but when learning it is sort of normal that you will be confused.

Try to break down and the explain the problem more clearly. First: provide the code you are actually using. I can't guess what's wrong if you aren't providing your code.

If you are saying that something crashes for you, make sure to tell us where it is crashing (exact line, not function). Use non-optimized builds with all debug information so you get asserts triggering and crashes with more accurate details.

Afaik the vanilla examples provided in examples/ would have no reason to ever crash in that function, so I assume you made modification to the examples (which raises the question of: why).

On 25 Jun 2017, at 07:26, mfriend notifications@github.com wrote:

I've been trying for three days to figure out how to get any of the examples to work at all, but I'm just constantly getting compiler errors and crashes

I don't understand what's going wrong here because I thought I was following what little documentation there is perfectly

clearly there's some sort of insider information that is just assumed to already be known here that I just don't know, because everything seems to assume that I already know something I clearly don't

what the hell am I doing wrong? I finally got one of the examples to compile, but it immediately crashes at " ImFontAtlas::GetTexDataAsAlpha8(unsigned char* out_pixels, int out_width, int* out_height, int* out_bytes_per_pixel)" with an "Unhandled exception at 0x001E20B6 in Test2.exe: 0xC0000005: Access violation reading location 0x00000004" error

―
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@dpethes I'm using vs2013

and @ocornut I provided a link to thecode in an earlier comment, I don't believe I changed any of the code, so it should be pretty much a verbatim copy except for making sure the includes are pointed to the correct places where my libraries are installed

Please include your project file and show us where the code is actually crashing. I also don't understand what would crash here.

(Although that also works, You shouldn't need to modify #include statements in the original sources. Instead you can setup the compiler with additional include directories)

You've commented out loading of fonts? And its crashing when creating the font atlas.. probably related.

It works without loading any fonts (those commented lines are in the example). The atlas build adds the default font if there's none.

alright I've changed my https://github.com/mfriendc/test2 repository to have all of the project files inside

I'm using example3 instead but it's crashing with an access violation in the same type of way: GetTexDataAtRGBA32 at the line "if (!TexPixelsRGBA32)" meaning it can't access its member variable I assume

(I THINK it saved the post-build event properly, otherwise you may have to copy sdl2.dll into the build folder yourself, unfortunately)

as far as I know, I'm not modifying anything, and these should be basically almost exact copies of the provided example files, so I'm not sure how the pointers could have gotten messed up

Hi,
I just tested on Linux, and I confirm :

  • your code CANNOT compile on -whatever platform- without being modified ;
  • you should learn what is behind "#include " logical

Do you have installed opengl32 ? Are you sure you installed a working OpenGL driver on your windows btw ?
Maybe a track : I suppose your windows 32 bits, right ? Do you compile 32 bits solutions or 64 bits ? (there is some strange Win32 things in your solution file, but I don't know Visual Studio (the last I used was 2008 ;-)

Now, I got suggestions if you want to test the code a safer way:

  1. Start creating the following path (directories and subdirectories) in the Root dir (Test2 if I'm not wrong) :
    inc/gl3w/GL ( "/" is a separator who means gl3w is a subdir of inc, and GL a subdir of gl3w )
    inc/imgui
    sources
    sources/imgui
    sources/gl3w

  2. Now put al the .h files (aka header files) inside the relevant -consistent- folders:
    More precisely:

  3. put gl3w.h and glcorearb.h in inc/gl3w/GL else they WON'T be found at compile time (or you forgot to tell us you modified the code, or installed (more crappy) another libglew + headers elsewhere)
  4. put imgui_impl_sdl_gl3.h in inc/imgui
  5. put all other imgui*.h in inc/imgui
  6. put all stb_*.h files in inc/imgui

  7. the .cpp files now:

  8. please put gl3w.c in sources/gl3w
  9. put all imgui*.cpp in sources/imgui including imgui_impl_sdl_gl3.cpp (of course)
  10. last keep Source.cpp at the root.

For the .dll now : don't forget to use the right path for opengl32 and SDL2 (in your VS configuration)

At the end, change ALL the path for includes in your (Visual Studio I suppose ?) solution file. It means you MUST use inc/gl3w and inc/imgui as include dirs to find the right .h files at compile time AND only use sources + sources/gl3w + sources/imgui + root dir as path for the .cpp files ... and retry the compilation.

IMHO, if you follow that, everything should be more consistent and provide better results, means could consist in a nice beginning if you want to study ImGui ;-) And if something really went wrong, we will be able to help you.

I forgot : If you are interested, that's exactly what I did it to test your code. It works perfectly on Linux, without a glitch, just using a better path for includes and .cpp files. Once this done, you should be able to track and understand what happens on your Windows more efficiently.

HTH

Chiming in a little:

put imgui_impl_sdl_gl3.h in inc/imgui
put all other imgui.h in inc/imgui
put all stb_
.h files in inc/imgui
put all imgui*.cpp in sources/imgui including imgui_impl_sdl_gl3.cpp (of course)

I find it strange that you are advocating making manual explicit changes compared to using a vanilla sources distribution. For anything pertaining to any open-source software, I think the ideal step should be:

checkout/unzip into a folder, don't touch anything

@ebachard the thing is, it compiles fine, but gets an access violation when running, so I don't know if it's a compiling problem, I can try to shuffle around the includes like that and see if it works, but I'm not very comfortable doing that

and opengl is working, because I got GLFW to work on its own in another test, and I have a window running with that checking keyboard inputs and what-not, I essentially did what @ocornut said which is download the examples, install the libraries without changing them, and pointed VS2013 to the libraries, and compiled

Did you debug loading your font? Could be as simple as you are loading a font file from a particular directory but you didn't set your working directory to allow it to be found and then are passing nullptrs around and ultimately crashing.

@ocornut you're right, this can look strange, but I'm used to explain and invite people to experiment, and understand what they are doing, instead of just being directive. Just my vision of free software world, and apologies if I offended people doing that :-) And of course, there is no problem if people correct me when I'm wrong.

@mfriendc : using your code (means : git clone your_repo without modify anything), I don't see how the preprocessor can solve #include in gl3w.h at build time, with the information you provided, since there is NO existing GL directory in your tree (excepted if you added another glcorearb.h somewhere in some GL folder, and in this case your build is plain wrong, and can lead to unpredictable behaviour). So, either you forgot to explain us something, or ... ?

@ebachard nobody's offended :) i just found it unusual to suggest that.

AFAIK we still don't have a callstack and the commited folders suggests that, @mfriendc hasn't build his application in Debug mode yet. And you are right about the GL directory that this cannot possibly compile. This is very likely not a problem with imgui but rather with user being confused by C++ ecosystems, so i'll close the topic but feel free to continue posting here if you want to help each others on this. The problem may be best solved on forums like stackoverflow where they would force you to narrow it down with clear explanations.

Not trying to be rude, but perhaps it would be better for the OP to start with a less "hostile" programming language / environment (I myself wouldn't recommend C/C++ for a beginner, but ymmv).

ive been doing c++ for a while, I just meant beginner as in beginner to gui libraries, if that makes any sense

strange, why not post basic things like call stack etc then?

@mfriend,
We're trying to help you but it's difficult since the provided information is a little confusing and suggests that you aren't yet very familiar with c++. If you provided a callstack and compiled in debug mode with assert enabled (which would be by default in a Debug project in visual studio), we'd have more data to guide you.
The problem is unlikely to be imgui's fault because this code has been well exercised in the past and your setup is fairly standard.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dowit picture dowit  Â·  3Comments

DarkLinux picture DarkLinux  Â·  3Comments

SlNPacifist picture SlNPacifist  Â·  3Comments

NPatch picture NPatch  Â·  3Comments

noche-x picture noche-x  Â·  3Comments