LWJGL exception (I don't know why) when applying textures [duplicate] - exception

This question already has answers here:
No OpenGL context found in the current thread, how do I fix this error?
(5 answers)
Closed 6 years ago.
So I am making a game in LWJGL (2 I think) and I have been working on a tile grid. but when I am binding my textures I am getting an exception and the game won't open (obviously) so I have been trying to solve this for an hour but I can't seem to get it to work. here is my code, can someone correct it for me?
FILEPATH:
code: (main class)
http://pastebin.com/GvxEyGRQ
code: (GridHandler class)
http://pastebin.com/2fcwLXU5
code: (TileType class - it is an enum)
http://pastebin.com/Dk0v3BRc
code: (Tile class)
http://pastebin.com/TNATAjJW
code: (renderer class)
http://pastebin.com/MBhReiAb
my error:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: No OpenGL context found in the current thread.
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
at org.lwjgl.opengl.GL11.glGetError(GL11.java:1299)
at org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer.glGetError(ImmediateModeOGLRenderer.java:384)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:249)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:200)
at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:64)
at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:24)
at Functions.renderer.loadTexture(renderer.java:58)
at Functions.renderer.quickLoad(renderer.java:67)
at Window.Tile.(Tile.java:20)
at Window.GridHandler.(GridHandler.java:30)
at Window.Main.(Main.java:31)
Thanks in advance,
Bryan.

I think it might be because your static GridHandler grid = new GridHandler(map) is instantiated before the main method.
You create the context in the beginning of your main method but the GridHandler is instantiated before the main() and therefore the context hasn't been created yet and you try to load texture with quickload method from the renderer in your TileHandler class - map[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.stone);
In order to execute gl commands you need a context first(Display.create() creates the current context). What TextureLoader does is that it loads the texture on the GPU(therefore executing commands).

Related

Why am I getting an attribute error with Pygame when I try to call a method on my targets? [duplicate]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have a class MyThread. In that, I have a method sample. I am trying to run it from within the same object context. Please have a look at the code:
class myThread (threading.Thread):
def __init__(self, threadID, name, counter, redisOpsObj):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter
self.redisOpsObj = redisOpsObj
def stop(self):
self.kill_received = True
def sample(self):
print "Hello"
def run(self):
time.sleep(0.1)
print "\n Starting " + self.name
self.sample()
Looks very simple ain't it. But when I run it I get this error
AttributeError: 'myThread' object has no attribute 'sample' Now I have that method, right there. So what's wrong? Please help
Edit: This is the stack trace
Starting Thread-0
Starting Thread-1
Exception in thread Thread-0:
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner
self.run()
File "./redisQueueProcessor.py", line 51, in run
self.sample()
AttributeError: 'myThread' object has no attribute 'sample'
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner
self.run()
File "./redisQueueProcessor.py", line 51, in run
self.sample()
AttributeError: 'myThread' object has no attribute 'sample'
I am calling it like this
arThreads = []
maxThreads = 2;
for i in range( maxThreads ):
redisOpsObj = redisOps()
arThreads.append( myThread(i, "Thread-"+str(i), 10, redisOpsObj) )
Sorry, I can't post the redisOps class code. But I can assure you that it works just fine
Your indentation is goofed, and you've mixed tabs and spaces. Run the script with python -tt to verify.
If you’re using python 3+ this may also occur if you’re using private variables that start with double underscore, e.g., self.__yourvariable. Just something to take note of for some of you who may run into this issue.
These kind of bugs are common when Python multi-threading. What happens is that, on interpreter tear-down, the relevant module (myThread in this case) goes through a sort-of del myThread.
The call self.sample() is roughly equivalent to myThread.__dict__["sample"](self).
But if we're during the interpreter's tear-down sequence, then its own dictionary of known types might've already had myThread deleted, and now it's basically a NoneType - and has no 'sample' attribute.
This may also occur if your using slots in class and have not added this new attribute in slots yet.
class xyz(object):
"""
class description
"""
__slots__ = ['abc', 'ijk']
def __init__(self):
self.abc = 1
self.ijk = 2
self.pqr = 6 # This will throw error 'AttributeError: <name_of_class_object> object has no attribute 'pqr'
I got this error for multi-threading scenario (specifically when dealing with ZMQ). It turned out that socket was still being connected on one thread while another thread already started sending data. The events that occured due to another thread tried to access variables that weren't created yet. If your scenario involves multi-threading and if things work if you add bit of delay then you might have similar issue.
Python protects those members by internally changing the name to include the class name.
You can access such attributes as object._className__attrName.
I have encountered the same error as well. I am sure my indentation did not have any problem. Only restarting the python sell solved the problem.
The same error occurred when I had another variable named mythread. That variable overwrote this and that's why I got error
You can't access outside private fields of a class. private fields are starting with __ .
for example -
class car:
def __init__(self):
self.__updatesoftware()
def drive(self):
print("driving")
def __updatesoftware(self):
print("updating software:")
obj = car()
obj.drive()
obj.__updatesoftware() ## here it will throw an error because
__updatesoftware is an private method.

ActionScript error: Compile Time Composite not found

I have been frustrated with this simple piece of code for quite some time now. I am just about to give up. Pretty much I am trying to make two objects react when they hit together, however I constantly get this error:
Scene 1, Layer 'hero', Frame 1, Line 27 1046: Type was not found or was not a compile-time constant: hit.
This is the Class file (that I am sure I am doing something wrong in to):
After reviewing your code, there doesn't seem to be anything wrong. With that said, one or more of the following may be causing your issue:
In File -> ActionScript Settings, you may have a value that is greater than 1 for this field:
Similarly, you may have unchecked this field 'Export in frame 1' when creating your symbol.
If the former, your symbol hit will not be available until your SWF has reached the frame that you entered. If the latter, your symbol hit will not be available until your SWF passes over a frame that you have placed it on.
The problem is in line:
var hit:hit = new hit();
You have a conflict of class name and instance, rename local variable and use it everywhere:
var hit1:hit = new hit();

Adobe Air AS3, disposing a window, profiler suggests library code

My application creates a window with a few Groups. When the window is closed, the window and it's descendents are not collected by the GC.
The Flash Builder Profiler helped me find and remove event listeners to the point where i am unable to spot the problem, since it points to event listeners added from the library code of Window.as.
Specifically, comparing the Loitering Objects from before window open and after window close, and choosing the MyWin class (1 instance):
MyPackageName.MyWin (10 Paths)
10x the following line:
Function [savedThis] 569222 GCRoot:Yes bytes:308
Clicking each "Function" in the Method panel i see the following 10 at the top of each "Function":
spark.components:Window:creationCompleteHandler() Window.as line 2610
spark.components:Window:creationCompleteHandler() Window.as line 2613
spark.components:Window:creationCompleteHandler() Window.as line 2616
spark.components:Window:creationCompleteHandler() Window.as line 2619
spark.components:Window:creationCompleteHandler() Window.as line 2625
spark.components:Window:creationCompleteHandler() Window.as line 2639
spark.components:Window:creationCompleteHandler() Window.as line 2636
Spark.components.supportClasses:SkinnableComponent:attachSkin() SkinnableComponent.as line 694
Spark.components:SkinnableContainer:partAdded() SkinnableContainter.as line 959
Spark.components:SkinnableContainer:partAdded() SkinnableContainter.as line 957
All these are invoked from a MyWin.initialize() in some manner.
I have removed every event listener created by my code, and removed all transitions.
but still unable to figure the meaning of this and how can i dispose of the window.
Any help, would be greatly appreciated since I've been struggling for a few days now.
You can try to use
System.pauseForGCIfCollectionImminent(1)
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/System.html#pauseForGCIfCollectionImminent%28%29
or try to use
System.gc()
in this way
private var numCollected; uint = 0;
private function gCollect(): void
{
addEventListeners(Event.ENTER_FRAME, onEFGCollect);
}
private function onEFGCollect(event: Event): void
{
numCollected++;
System.gc();
if(numCollected > 2)
removeEventListeners(Event.ENTER_FRAME, onEFGCollect);
}
there we use System.gc() two times in separate frames just because to collect object it's need to mark all of them as collected - and only after that System.gc() can collect objects.
As far as I know the best way is to make sure all references to the window in question are set to null. I have looked into this before and could not find any direct way to get the garbage collector to work immediately.

NUnit / Moq throwing a NullReferenceException error on the constructor of a variable

I am using Moq, NUnit, WPF, MVVM, Ninject.
I am writing a test for my LoginViewModel, and in the test when I use the constructor of the LoginViewModel to create a new instance, I am getting a NullReferenceException error. The code compiles and runs, (i.e. when I run the program the LoginView shows, and works with the LoginViewModel to create the correct behaviour etc) but for some reason the UnitTest is crashing.
this is the constructor:
public LoginViewModel(ILoginServices loginServices,IDialogService dialogServices)
{
InitializeFields();
_loginServices = loginServices;
_dialogService = dialogServices;
DomainList = _loginServices.GetDomainListing();
}
I have mocked the dependencies as follows:
Mock<ILoginServices> moq = new Mock<ILoginServices>();
moq.Setup(log =>
log.LoginUser(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback<string, string, string>((i, j, k) => CheckArgs(i, j, k));
moq.Setup(log2 =>
log2.GetDomainListing()).Returns(new List<string> { "Domain" });
Mock<IDialogService> moq2 = new Mock<IDialogService>();
I have also tried inserting real services as the parameters.
I have verified that the mocks do work, and the objects these mocks
return are not null.
I have commented out all the code in the constructor.
I have tried inserting the line
LoginViewModel test = new LoginViewModel(_fakeLoginService,_fakeDialogService);
in front of the call to the constructor (to see if it had to do with the original local variable being disposed or something before) and this line crashed instead.
From all I can see this must be the constructor,(but not the code I have written inside it) and that this is solely related to NUnit / Moq as my code still compiles and runs fine.
I have no idea on this one guys, can anyone point me in the right direction?
[Edit]
Ok so I have run through the code and the error comes from this line of code:
ImageSource = (ImageSource)Application.Current.FindResource(_imageName);
This code is going to a ImageDictionary and getting a reference to the image for an undo button in the WindowViewModel (which my LoginViewModel inherits).
My hypotheses as to why its working in the normal running of the application, but not in the testing are:
1) Because I am running the program code through NUnit, the Application.Current object isnt getting property assigned/there is no Application.Current object to get.
**or**
2) Something to do with the fact that because the program code is being run in NUnit, the code doesn't have access to/can't resolve the ImageDictionary to find the image.
I'm leaning more strongly to the first hypothesis, but I'm as of yet not 100% sure, and I am having trouble finding the values of the Application.Current at runtime, cause when I move my cursor over the code the tooltip that normally appears showing the detail of the object that is not appearing.
My new question is: Does any of this make sense? Do you guys know if the Application.Current object exists / can be accessed when running the testing project through NUnit?
Any help will be appreciated.
You are correct. Application.Current is null for Unit tests. You can work around this by injecting the Application object as referencing singletons in code can make life tricky.

TypeError: Error #1009 Actionscript 3

I am extremely frustrated. I'm following a tutorial and mimicing it on my own. I have been able to sort out most of the errors so far but this one has me stumped. I have tried replacing all of the class files with the tutorial specimen ones but i still get the error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.senocular.utils::KeyObject/construct()
at com.senocular.utils::KeyObject()
at com.asgamer.basics1::Ship()
at com.asgamer.basics1::Engine()
Now, not really understanding the error properly I paste dumped the files online for you to look at.
Ship class: textbin.com/78z35
Engine class: textbin.com/32b24
KeyObject class: textbin.com/p2725
As the error still occured when using the specimen class files I really have no idea where to begin. I will gladly try out any suggestions.
Tip: If you allow debugging, the exception will tell you the exact line in the source code where the Error is being thrown. Assuming you're using the Flash IDE, go to publish settings and in the Flash tab check "Permit debugging". This will makes thing much easier for you.
Anyway, you have an error message. If you read it carefully, you can narrow down where the problem is. I don't know if you are a programmer or you have any interest in being one; if you're not, this answer will hopefully solve this particular problem. Anyway, if you don't mind the rambling, let me tell you that if you're interested in becoming a better programmer, paying attention to errors and learning how to debug / troubleshoot problems is one of the most important abilities you need to develop (if not the most important one); so maybe this will give you a few hints you can use to solve other problems as well.
The message says:
Cannot access a property or method of
a null object reference.
This means, at some point, you did something like this:
someobject.someMethod();
or
someobject.someProperty = "foo";
And someobject happened to be null. You can't call methods or access properties of null.
Ok, so now you know, somewhere, a variable had null as its value. Notice that the fact that you define a variable of property doesn't mean it actually holds an object.
This just says that a variable called mySprite can hold an object of the type Sprite:
var mySprite:Sprite;
But until at some point you create a Sprite and assign it to mySprite, the value held by mySprite will be null. If you do:
mySprite.x = 0;
Before initializing mySprite (i.e. before assigning a Sprite to it), you will have this same Null Reference error.
This error message also offers some helpul context, which you can use to your advantage (in them old days... errors in Flash were silent; when things didn't work, you had to manually trace down the problem).
Ok, let's break this error message down:
at com.senocular.utils::KeyObject/construct()
at com.senocular.utils::KeyObject()
at com.asgamer.basics1::Ship()
at com.asgamer.basics1::Engine()
What you have above is called a stack trace. It basically tells you where the code blew up, and also gives you some context: how did you get there.
The first line tells where the error actually occurred. That is, the construct method in the KeyObject object. That method was called from the KeyObject constructor, which was in turn called from the Ship constructor, which was in turn called from the Engine constructor.
Now, let's analyze how you got there, following the stack trace, bottom-up:
Code in Engine constructor:
ourShip = new Ship(stage);
This creates a new Ship object. It passes a reference to the stage to the Ship constructor method.
Code in Ship constructor:
this.stageRef = stageRef;
key = new KeyObject(stageRef);
It grabs the ref passed in the previous step. It stores it and creates a new KeyObject object. The KeyObject constructor is passed a reference to the stage (which is the same ref that was passed from Engine to Ship).
Code in KeyObject constructor:
KeyObject.stage = stage;
keysDown = new Object();
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
Now we got to the point where the error message told you the problem was. So, somewhere, you are using a variable that holds null and trying to access one of its methods or properties.
This KeyObject stores the reference to stage it was passed in a static variable and creates a new Object object. So far, no problems. KeyObject cannot be null (it's a reference to a Class). The second line itself cannot have this null problem either. So, if this is all the code in that method, the problem has to be either in the third or the fourth line. Both access the stage reference you passed and try to call a method (addEventListener) on it. So if one fails, the other will fail as well. Then, the third line: that's where the problem has to be.
So, at that point stage is null. As said previously, you can't call a method on null, and that's what the error is telling you.
Now, if you get back to the first method call, you can see this is the origin of the problem:
ourShip = new Ship(stage);
You can be pretty sure that, at this point, stage was null. Add that to the fact that Engine extends MovieClip (which is in turn a DisplayObject), and to the fact that any DisplayObject has a reference to the stage object only while it's added to the display list. The conclusion: an instance of Engine was not attached to the display list when its constructor was ran.
A way to fix this (there might be others) could be moving the code in the Engine constructor to a separate function that will be executed only if / when the Engine object has a valid reference to the stage object.
public function Engine() : void {
if(stage) {
initialize();
} else {
addEventListener(Event.ADDED_TO_STAGE,initialize);
}
}
private function initialize(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE,initialize);
// here goes the code that's currently in Engine constructor
}
Hope this helps.
I have a feeling your stage property is null.
You have have to test this yourself with a trace of the stage object.
In the first line in the constructor of you Engine class, add:
trace(stage);
Add that just above this line:
ourShip = new Ship(stage);
If it traces "null" then that is your problem.