Search Results

Search found 19292 results on 772 pages for 'jack null'.

Page 10/772 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Calling a method on an unitialized object (null pointer)

    - by Florin
    What is the normal behavior in Objective-C if you call a method on an object (pointer) that is nil (maybe because someone forgot to initialize it)? Shouldn't it generate some kind of an error (segmentation fault, null pointer exception...)? If this is normal behavior, is there a way of changing this behavior (by configuring the compiler) so that the program raises some kind of error / exception at runtime? To make it more clear what I am talking about, here's an example. Having this class: @interface Person : NSObject { NSString *name; } @property (nonatomic, retain) NSString *name; - (void)sayHi; @end with this implementation: @implementation Person @synthesize name; - (void)dealloc { [name release]; [super dealloc]; } - (void)sayHi { NSLog(@"Hello"); NSLog(@"My name is %@.", name); } @end Somewhere in the program I do this: Person *person = nil; //person = [[Person alloc] init]; // let's say I comment this line person.name = @"Mike"; // shouldn't I get an error here? [person sayHi]; // and here [person release]; // and here

    Read the article

  • Passing NULL value

    - by FFXIII
    Hi. I use an instance of NSXMLParser. I store found chars in NSMutableStrings that are stored in an NSMutableDictionary and these Dicts are then added to an NSMutableArray. When I test this everything seems normal: I count 1 array, x dictionnaries and x strings. In a detailview controller file I want to show my parsed results. I call the class where everthing is stored but I get (null) returned. This is what I do (wrong): XMLParser.h @interface XMLParser : NSObject { NSMutableArray *array; NSMUtableDictionary *dictionary; NSSMutabletring *element; } @property (nonatomic, retain) NSMutableArray *array; @property (nonatomic, retain) NSMutableDictionary *dictionary; @property (nonatomic, retain) NSMutableString *element; XMLParser.m @synthesize array, dictionary, element; //parsing goes on here & works fine //so 'element' is filled with content and stored in a dict in an array //and released at the end of the file In my controller file I do this: controller.h @class XMLParser; @interface controller : UIViewController { XMLParser *aXMLParser; } @property (nonatomic, retain) XMLParser *aXMLParser; controller.m #import "XMLParser.h" @synthesize aXMLParser; - (void)viewDidLoad { NSLog(@"test array: %@", aXMLParser.array); NSLog(@"test dict: %@", aXMLParser.dictionary); NSLog(@"test element: %@", aXMLParser.element); } When I test the value of my array, a dict or an element in the XMLParser.h file I get my result. What am I doing wrong so I can't call my results in my controller file? Any help is welcome, because I'm pretty stuck right now :/

    Read the article

  • Get the parent class of a null object (C# Reflection)

    - by Nick
    How would I get the parent class of an object that has a value of null? For example... 'Class A' contains 'int? i' which is not set to any value when the class is created. Then in some other place in the code I want to pass in 'i' as a parameter to some function. Using 'i' as the only info, I want to be able to figure out that 'Class A' "owns" 'i'. The reason for this is because 'Class A' also contains some other object, and I want to call this other object's value from that same function mentioned in the above paragraph. Could also be: public class A { public class B { public int? i; public int? j; } B classBInstance = new B(); public string s; } { ... A someClassAInstance = new A(); ... doSomething(someClassAInstance.classBInstance.i); ... } public static bool doSomething(object theObject) { string s = /* SOMETHING on theObject to get to "s" from Class A */; int someValue = (int)theObject; }

    Read the article

  • What are the disadvantages of self-encapsulation?

    - by Dave Jarvis
    Background Tony Hoare's billion dollar mistake was the invention of null. Subsequently, a lot of code has become riddled with null pointer exceptions (segfaults) when software developers try to use (dereference) uninitialized variables. In 1989, Wirfs-Brock and Wikerson wrote: Direct references to variables severely limit the ability of programmers to re?ne existing classes. The programming conventions described here structure the use of variables to promote reusable designs. We encourage users of all object-oriented languages to follow these conventions. Additionally, we strongly urge designers of object-oriented languages to consider the effects of unrestricted variable references on reusability. Problem A lot of software, especially in Java, but likely in C# and C++, often uses the following pattern: public class SomeClass { private String someAttribute; public SomeClass() { this.someAttribute = "Some Value"; } public void someMethod() { if( this.someAttribute.equals( "Some Value" ) ) { // do something... } } public void setAttribute( String s ) { this.someAttribute = s; } public String getAttribute() { return this.someAttribute; } } Sometimes a band-aid solution is used by checking for null throughout the code base: public void someMethod() { assert this.someAttribute != null; if( this.someAttribute.equals( "Some Value" ) ) { // do something... } } public void anotherMethod() { assert this.someAttribute != null; if( this.someAttribute.equals( "Some Default Value" ) ) { // do something... } } The band-aid does not always avoid the null pointer problem: a race condition exists. The race condition is mitigated using: public void anotherMethod() { String someAttribute = this.someAttribute; assert someAttribute != null; if( someAttribute.equals( "Some Default Value" ) ) { // do something... } } Yet that requires two statements (assignment to local copy and check for null) every time a class-scoped variable is used to ensure it is valid. Self-Encapsulation Ken Auer's Reusability Through Self-Encapsulation (Pattern Languages of Program Design, Addison Wesley, New York, pp. 505-516, 1994) advocated self-encapsulation combined with lazy initialization. The result, in Java, would resemble: public class SomeClass { private String someAttribute; public SomeClass() { setAttribute( "Some Value" ); } public void someMethod() { if( getAttribute().equals( "Some Value" ) ) { // do something... } } public void setAttribute( String s ) { this.someAttribute = s; } public String getAttribute() { String someAttribute = this.someAttribute; if( someAttribute == null ) { setAttribute( createDefaultValue() ); } return someAttribute; } protected String createDefaultValue() { return "Some Default Value"; } } All duplicate checks for null are superfluous: getAttribute() ensures the value is never null at a single location within the containing class. Efficiency arguments should be fairly moot -- modern compilers and virtual machines can inline the code when possible. As long as variables are never referenced directly, this also allows for proper application of the Open-Closed Principle. Question What are the disadvantages of self-encapsulation, if any? (Ideally, I would like to see references to studies that contrast the robustness of similarly complex systems that use and don't use self-encapsulation, as this strikes me as a fairly straightforward testable hypothesis.)

    Read the article

  • ASP.Net repeater item.DataItem is null

    - by mattgcon
    Within a webpage, upon loading, I fill a dataset with two table with a relation between those tables and then load the data into a repeater with a nested repeater. This can also occur after the user clicks on a button. The data gets loaded from a SQL database and the repeater datasource is set to the dataset after a postback. However, when ItemDataBound occurs the Item.Dataitem is always null. Why would this occur? below is my HTML repeater code <asp:Repeater ID="rptCustomSpaList" runat="server" onitemdatabound="rptCustomSpaList_ItemDataBound"> <HeaderTemplate> </HeaderTemplate> <ItemTemplate> <table> <tr> <td> <asp:Label ID="Label3" runat="server" Text="Spa Series:"></asp:Label> </td> <td> <asp:Label ID="Label4" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "SPASERIESVALUE") %>'></asp:Label> </td> </tr> <tr> <td> <asp:Label ID="Label5" runat="server" Text="Spa Model:"></asp:Label> </td> <td> <asp:Label ID="Label6" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "SPAMODELVALUE") %>'></asp:Label> </td> </tr> <tr> <td> <asp:Label ID="Label9" runat="server" Text="Acrylic Color:"></asp:Label> </td> <td> <asp:Label ID="Label10" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "ACRYLICCOLORVALUE") %>'></asp:Label> </td> </tr> <tr> <td> <asp:Label ID="Label11" runat="server" Text="Cabinet Color:"></asp:Label> </td> <td> <asp:Label ID="Label12" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CABPANCOLORVALUE") %>'></asp:Label> </td> </tr> <tr> <td> <asp:Label ID="Label17" runat="server" Text="Cabinet Type:"></asp:Label> </td> <td> <asp:Label ID="Label18" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CABINETVALUE") %>'></asp:Label> </td> </tr> <tr> <td> <asp:Label ID="Label13" runat="server" Text="Cover Color:"></asp:Label> </td> <td> <asp:Label ID="Label14" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "COVERCOLORVALUE") %>'></asp:Label> </td> </tr> </table> <asp:Label ID="Label15" runat="server" Text="Options:"></asp:Label> <asp:Repeater ID="rptCustomSpaItem" runat="server"> <HeaderTemplate> <table> </HeaderTemplate> <ItemTemplate> <tr> <td> <asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "PROPERTY") %>'></asp:Label> </td> <td> <asp:Label ID="Label2" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "VALUE") %>'></asp:Label> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <table> <tr> <td style="padding-top:15px;padding-bottom:30px;"> <asp:Label ID="Label7" runat="server" Text="Configured Price:"></asp:Label> </td> <td style="padding-top:15px;padding-bottom:30px;"> <asp:Label ID="Label8" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "SPAVALUEVALUE") %>'></asp:Label> </td> </tr> </table> <asp:Label ID="Label16" runat="server" Text="------"></asp:Label> </ItemTemplate> <FooterTemplate></FooterTemplate> </asp:Repeater>

    Read the article

  • C# ?? null coalescing operator

    - by anirudha
    the null coalescing operator is used for set the value when object is null. if object have some value that nothing change and still have their default value they have.  string str = "i am string";            string message = str ?? "it is null";   the message have same value as str variable because str not null. if str is null that message have value “it is null”; as declared in statement. coalescing operator does not work on nullable operator such as int?

    Read the article

  • How to simulate inner join on very large files in java (without running out of memory)

    - by Constantin
    I am trying to simulate SQL joins using java and very large text files (INNER, RIGHT OUTER and LEFT OUTER). The files have already been sorted using an external sort routine. The issue I have is I am trying to find the most efficient way to deal with the INNER join part of the algorithm. Right now I am using two Lists to store the lines that have the same key and iterate through the set of lines in the right file once for every line in the left file (provided the keys still match). In other words, the join key is not unique in each file so would need to account for the Cartesian product situations ... left_01, 1 left_02, 1 right_01, 1 right_02, 1 right_03, 1 left_01 joins to right_01 using key 1 left_01 joins to right_02 using key 1 left_01 joins to right_03 using key 1 left_02 joins to right_01 using key 1 left_02 joins to right_02 using key 1 left_02 joins to right_03 using key 1 My concern is one of memory. I will run out of memory if i use the approach below but still want the inner join part to work fairly quickly. What is the best approach to deal with the INNER join part keeping in mind that these files may potentially be huge public class Joiner { private void join(BufferedReader left, BufferedReader right, BufferedWriter output) throws Throwable { BufferedReader _left = left; BufferedReader _right = right; BufferedWriter _output = output; Record _leftRecord; Record _rightRecord; _leftRecord = read(_left); _rightRecord = read(_right); while( _leftRecord != null && _rightRecord != null ) { if( _leftRecord.getKey() < _rightRecord.getKey() ) { write(_output, _leftRecord, null); _leftRecord = read(_left); } else if( _leftRecord.getKey() > _rightRecord.getKey() ) { write(_output, null, _rightRecord); _rightRecord = read(_right); } else { List<Record> leftList = new ArrayList<Record>(); List<Record> rightList = new ArrayList<Record>(); _leftRecord = readRecords(leftList, _leftRecord, _left); _rightRecord = readRecords(rightList, _rightRecord, _right); for( Record equalKeyLeftRecord : leftList ){ for( Record equalKeyRightRecord : rightList ){ write(_output, equalKeyLeftRecord, equalKeyRightRecord); } } } } if( _leftRecord != null ) { write(_output, _leftRecord, null); _leftRecord = read(_left); while(_leftRecord != null) { write(_output, _leftRecord, null); _leftRecord = read(_left); } } else { if( _rightRecord != null ) { write(_output, null, _rightRecord); _rightRecord = read(_right); while(_rightRecord != null) { write(_output, null, _rightRecord); _rightRecord = read(_right); } } } _left.close(); _right.close(); _output.flush(); _output.close(); } private Record read(BufferedReader reader) throws Throwable { Record record = null; String data = reader.readLine(); if( data != null ) { record = new Record(data.split("\t")); } return record; } private Record readRecords(List<Record> list, Record record, BufferedReader reader) throws Throwable { int key = record.getKey(); list.add(record); record = read(reader); while( record != null && record.getKey() == key) { list.add(record); record = read(reader); } return record; } private void write(BufferedWriter writer, Record left, Record right) throws Throwable { String leftKey = (left == null ? "null" : Integer.toString(left.getKey())); String leftData = (left == null ? "null" : left.getData()); String rightKey = (right == null ? "null" : Integer.toString(right.getKey())); String rightData = (right == null ? "null" : right.getData()); writer.write("[" + leftKey + "][" + leftData + "][" + rightKey + "][" + rightData + "]\n"); } public static void main(String[] args) { try { BufferedReader leftReader = new BufferedReader(new FileReader("LEFT.DAT")); BufferedReader rightReader = new BufferedReader(new FileReader("RIGHT.DAT")); BufferedWriter output = new BufferedWriter(new FileWriter("OUTPUT.DAT")); Joiner joiner = new Joiner(); joiner.join(leftReader, rightReader, output); } catch (Throwable e) { e.printStackTrace(); } } } After applying the ideas from the proposed answer, I changed the loop to this private void join(RandomAccessFile left, RandomAccessFile right, BufferedWriter output) throws Throwable { long _pointer = 0; RandomAccessFile _left = left; RandomAccessFile _right = right; BufferedWriter _output = output; Record _leftRecord; Record _rightRecord; _leftRecord = read(_left); _rightRecord = read(_right); while( _leftRecord != null && _rightRecord != null ) { if( _leftRecord.getKey() < _rightRecord.getKey() ) { write(_output, _leftRecord, null); _leftRecord = read(_left); } else if( _leftRecord.getKey() > _rightRecord.getKey() ) { write(_output, null, _rightRecord); _pointer = _right.getFilePointer(); _rightRecord = read(_right); } else { long _tempPointer = 0; int key = _leftRecord.getKey(); while( _leftRecord != null && _leftRecord.getKey() == key ) { _right.seek(_pointer); _rightRecord = read(_right); while( _rightRecord != null && _rightRecord.getKey() == key ) { write(_output, _leftRecord, _rightRecord ); _tempPointer = _right.getFilePointer(); _rightRecord = read(_right); } _leftRecord = read(_left); } _pointer = _tempPointer; } } if( _leftRecord != null ) { write(_output, _leftRecord, null); _leftRecord = read(_left); while(_leftRecord != null) { write(_output, _leftRecord, null); _leftRecord = read(_left); } } else { if( _rightRecord != null ) { write(_output, null, _rightRecord); _rightRecord = read(_right); while(_rightRecord != null) { write(_output, null, _rightRecord); _rightRecord = read(_right); } } } _left.close(); _right.close(); _output.flush(); _output.close(); } UPDATE While this approach worked, it was terribly slow and so I have modified this to create files as buffers and this works very well. Here is the update ... private long getMaxBufferedLines(File file) throws Throwable { long freeBytes = Runtime.getRuntime().freeMemory() / 2; return (freeBytes / (file.length() / getLineCount(file))); } private void join(File left, File right, File output, JoinType joinType) throws Throwable { BufferedReader leftFile = new BufferedReader(new FileReader(left)); BufferedReader rightFile = new BufferedReader(new FileReader(right)); BufferedWriter outputFile = new BufferedWriter(new FileWriter(output)); long maxBufferedLines = getMaxBufferedLines(right); Record leftRecord; Record rightRecord; leftRecord = read(leftFile); rightRecord = read(rightFile); while( leftRecord != null && rightRecord != null ) { if( leftRecord.getKey().compareTo(rightRecord.getKey()) < 0) { if( joinType == JoinType.LeftOuterJoin || joinType == JoinType.LeftExclusiveJoin || joinType == JoinType.FullExclusiveJoin || joinType == JoinType.FullOuterJoin ) { write(outputFile, leftRecord, null); } leftRecord = read(leftFile); } else if( leftRecord.getKey().compareTo(rightRecord.getKey()) > 0 ) { if( joinType == JoinType.RightOuterJoin || joinType == JoinType.RightExclusiveJoin || joinType == JoinType.FullExclusiveJoin || joinType == JoinType.FullOuterJoin ) { write(outputFile, null, rightRecord); } rightRecord = read(rightFile); } else if( leftRecord.getKey().compareTo(rightRecord.getKey()) == 0 ) { String key = leftRecord.getKey(); List<File> rightRecordFileList = new ArrayList<File>(); List<Record> rightRecordList = new ArrayList<Record>(); rightRecordList.add(rightRecord); rightRecord = consume(key, rightFile, rightRecordList, rightRecordFileList, maxBufferedLines); while( leftRecord != null && leftRecord.getKey().compareTo(key) == 0 ) { processRightRecords(outputFile, leftRecord, rightRecordFileList, rightRecordList, joinType); leftRecord = read(leftFile); } // need a dispose for deleting files in list } else { throw new Exception("DATA IS NOT SORTED"); } } if( leftRecord != null ) { if( joinType == JoinType.LeftOuterJoin || joinType == JoinType.LeftExclusiveJoin || joinType == JoinType.FullExclusiveJoin || joinType == JoinType.FullOuterJoin ) { write(outputFile, leftRecord, null); } leftRecord = read(leftFile); while(leftRecord != null) { if( joinType == JoinType.LeftOuterJoin || joinType == JoinType.LeftExclusiveJoin || joinType == JoinType.FullExclusiveJoin || joinType == JoinType.FullOuterJoin ) { write(outputFile, leftRecord, null); } leftRecord = read(leftFile); } } else { if( rightRecord != null ) { if( joinType == JoinType.RightOuterJoin || joinType == JoinType.RightExclusiveJoin || joinType == JoinType.FullExclusiveJoin || joinType == JoinType.FullOuterJoin ) { write(outputFile, null, rightRecord); } rightRecord = read(rightFile); while(rightRecord != null) { if( joinType == JoinType.RightOuterJoin || joinType == JoinType.RightExclusiveJoin || joinType == JoinType.FullExclusiveJoin || joinType == JoinType.FullOuterJoin ) { write(outputFile, null, rightRecord); } rightRecord = read(rightFile); } } } leftFile.close(); rightFile.close(); outputFile.flush(); outputFile.close(); } public void processRightRecords(BufferedWriter outputFile, Record leftRecord, List<File> rightFiles, List<Record> rightRecords, JoinType joinType) throws Throwable { for(File rightFile : rightFiles) { BufferedReader rightReader = new BufferedReader(new FileReader(rightFile)); Record rightRecord = read(rightReader); while(rightRecord != null){ if( joinType == JoinType.LeftOuterJoin || joinType == JoinType.RightOuterJoin || joinType == JoinType.FullOuterJoin || joinType == JoinType.InnerJoin ) { write(outputFile, leftRecord, rightRecord); } rightRecord = read(rightReader); } rightReader.close(); } for(Record rightRecord : rightRecords) { if( joinType == JoinType.LeftOuterJoin || joinType == JoinType.RightOuterJoin || joinType == JoinType.FullOuterJoin || joinType == JoinType.InnerJoin ) { write(outputFile, leftRecord, rightRecord); } } } /** * consume all records having key (either to a single list or multiple files) each file will * store a buffer full of data. The right record returned represents the outside flow (key is * already positioned to next one or null) so we can't use this record in below while loop or * within this block in general when comparing current key. The trick is to keep consuming * from a List. When it becomes empty, re-fill it from the next file until all files have * been consumed (and the last node in the list is read). The next outside iteration will be * ready to be processed (either it will be null or it points to the next biggest key * @throws Throwable * */ private Record consume(String key, BufferedReader reader, List<Record> records, List<File> files, long bufferMaxRecordLines ) throws Throwable { boolean processComplete = false; Record record = records.get(records.size() - 1); while(!processComplete){ long recordCount = records.size(); if( record.getKey().compareTo(key) == 0 ){ record = read(reader); while( record != null && record.getKey().compareTo(key) == 0 && recordCount < bufferMaxRecordLines ) { records.add(record); recordCount++; record = read(reader); } } processComplete = true; // if record is null, we are done if( record != null ) { // if the key has changed, we are done if( record.getKey().compareTo(key) == 0 ) { // Same key means we have exhausted the buffer. // Dump entire buffer into a file. The list of file // pointers will keep track of the files ... processComplete = false; dumpBufferToFile(records, files); records.clear(); records.add(record); } } } return record; } /** * Dump all records in List of Record objects to a file. Then, add that * file to List of File objects * * NEED TO PLACE A LIMIT ON NUMBER OF FILE POINTERS (check size of file list) * * @param records * @param files * @throws Throwable */ private void dumpBufferToFile(List<Record> records, List<File> files) throws Throwable { String prefix = "joiner_" + files.size() + 1; String suffix = ".dat"; File file = File.createTempFile(prefix, suffix, new File("cache")); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); for( Record record : records ) { writer.write( record.dump() ); } files.add(file); writer.flush(); writer.close(); }

    Read the article

  • LINQ + Find count of non-null values

    - by Ashutosh
    I have a table with the below structure. ID VALUE 1 3.2 2 NULL 4 NULL 5 NULL 7 NULL 10 1.8 11 NULL 12 3.2 15 4.7 17 NULL 22 NULL 24 NULL 25 NULL 27 NULL 28 7 I would like to get the max count of consecutive null values in the table. Any help would be greatly appreciated. THanks Ashutosh

    Read the article

  • LINQ query null reference exception

    - by user289082
    Hi! I have the next query: var bPermisos = from b in ruc.Permisos where b.IdUsuario == cu.Id select new Permisos(){ Id=b.Id, IdUsuario=b.Id, IdPerfil=b.Id, Estatus=b.Estatus }; var qSisPer = from perm in bPermisos select new { perm.IdPerfil,perm.Cat_Perfil.Nivel,perm.Cat_Perfil.Nombre,Nombre_Sistem=perm.Cat_Perfil.Cat_Sistema.Nombre}; And is throwing me an exception, plz help!

    Read the article

  • What is wrong with this null check for data reader

    - by Phil
    c.Open() r = x.ExecuteReader If Not r("filename").IsDbnull Then imagepath = "<img src='images/'" & getimage(r("filename")) & " border='0' align='absmiddle'" End If c.Close() r.Close() I have also tried; If r("filename") Is DBNull.Value Then imagepath = String.Empty Else imagepath = "<img src='images/'" & getimage(r("filename")) & " border='0' align='absmiddle'" End If c.Close() r.Close() The error is: Invalid attempt to read when no data is present. The idea of my code is to build an img src string only when data is available. Help greatly appreciated. Thanks

    Read the article

  • 3.5 mm component video jack -> Ipod female connection?

    - by Jigs
    At my gym the treadmills all have ipod male cables hanging out of them so that you can plug in a video ipod and play a video directly to the screen on the treadmill. I own a non apple MP4 player is there an adapter that will go from a 3.5mm component video jack to a female ipod connector that will allow me to watch a film on the screen?

    Read the article

  • How to mix textures in DirectX?

    - by tobsen
    I am new to DirectX development and I am wondering if I am taking the wrong route to achieve the following: I would like to mix three textures which contain transparent areas and some solid areas (Red, Blue, Green). The three textures should blend like shown in this example: How can I achieve that in DirectX (preferably in directx9)? A link or example code would be nice. Update: My rendering method looks like this and I still think I am doing it wrong, because the sprite only shows the last texture (nothing is rendered transparent or blended): void D3DTester::render() { d3ddevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0); d3ddevice->BeginScene(); d3ddevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); d3ddevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); d3ddevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); LPD3DXSPRITE sprite=NULL; HRESULT hres = D3DXCreateSprite(d3ddevice, &sprite); if(hres != S_OK) { throw std::exception(); } sprite->Begin(D3DXSPRITE_ALPHABLEND); std::vector<LPDIRECT3DTEXTURE9>::iterator it; for ( it=textures.begin() ; it < textures.end(); it++ ) { sprite->Draw(*it, NULL, NULL, NULL, 0xFFFFFFFF); } sprite->End(); d3ddevice->EndScene(); d3ddevice->Present(NULL, NULL, NULL, NULL); } The resulting image looks like this: But I need it to look like this instead: Update2: I figured out that I have to SetRenderState after I use sprite->Begin(D3DXSPRITE_ALPHABLEND); thanks to the hint by Josh Petrie. However, by using this: sprite->Begin(D3DXSPRITE_ALPHABLEND); d3ddevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); d3ddevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); d3ddevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); std::vector<LPDIRECT3DTEXTURE9>::iterator it; for ( it=textures.begin() ; it < textures.end(); it++ ) { sprite->Draw(*it, NULL, NULL, NULL, 0xFFFFFFFF); } sprite->End(); The sprites colors are becoming transparent towards the background scene e.g.: if I use d3ddevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,100,21), 1.0f, 0); the result looks like: Is there any way to avoid that? I would like the sprites be transparent to each other but to be still solid to the background. Update3: After having sombody explained to me, how to do what @LaurentCouvidou and @JoshPetrie suggested, I have a working solution and therfore accept the answer: d3ddevice->BeginScene(); D3DCOLOR white = D3DCOLOR_RGBA((UINT)255, (UINT)255, (UINT)255, 255); D3DCOLOR black = D3DCOLOR_RGBA((UINT)0, (UINT)0, (UINT)0, 255); sprite->Begin(D3DXSPRITE_ALPHABLEND); sprite->Draw(pTextureRed, NULL, NULL, NULL, black); sprite->Draw(pTextureGreen, NULL, NULL, NULL, black); sprite->Draw(pTextureBlue, NULL, NULL, NULL, black); sprite->End(); sprite->Begin(D3DXSPRITE_ALPHABLEND); d3ddevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); d3ddevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); d3ddevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); d3ddevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); sprite->Draw(pTextureRed, NULL, NULL, NULL, white); sprite->Draw(pTextureGreen, NULL, NULL, NULL, white); sprite->Draw(pTextureBlue, NULL, NULL, NULL, white); sprite->End(); d3ddevice->EndScene(); d3ddevice->Present(NULL, NULL, NULL, NULL);

    Read the article

  • Lots of static/crackling noises after ALSA HDA DKMS installation

    - by MartinB
    I am using a Samsung Chronos 7 laptop with the following sound setup: $ head -n 1 /proc/asound/card0/codec* ==> /proc/asound/card0/codec#0 <== Codec: Realtek ALC269VC ==> /proc/asound/card0/codec#3 <== Codec: Intel CougarPoint HDMI With the stock ALSA that comes with Ubuntu 12.04, I do not get any sound out of the headphones when I plug them into the headphone jack. After plugging the headphones in, I have to manually use Alsamixer to increase the volume, so that the headphones become usable. I have been told that this issue is due to my sound chip not being supported in the ALSA version that ships with Precise. A similar question at AskUbuntu and the Ubuntu Community Documentation point me to the ALSA DKMS installation. After installing the dkms module of yesterday's ALSA snapshot and rebooting, the headphone issue is indeed solved. I can now plug my headphones into the jack and instantly have sound on them. However, now I have tons of static noises and crackling when playing sound in VLC player or Skype (Firefox HTML5 playback seems to be fine, unless a Skype sound interferes with it). Is there a fix for this? I tried adding the Alsa PPA and installing the latest ALSA package proper, but that didn't have any effect, only the Alsa DKMS package seems to solve the headphone issue.

    Read the article

  • Reportviewer stored procedure [closed]

    - by Liesl
    I want to write a stored procedure for my invoice reportviewer. After invoice is generated in reportviewer it must also add the data to my Invoice table. This is all my tables in my database: CREATE TABLE [dbo].[Waybills]( [WaybillID] [int] IDENTITY(1,1) NOT NULL, [SenderName] [varchar](50) NULL, [SenderAddress] [varchar](50) NULL, [SenderContact] [int] NULL, [ReceiverName] [varchar](50) NULL, [ReceiverAddress] [varchar](50) NULL, [ReceiverContact] [int] NULL, [UnitDescription] [varchar](50) NULL, [UnitWeight] [int] NULL, [DateReceived] [date] NULL, [Payee] [varchar](50) NULL, [CustomerID] [int] NULL, PRIMARY KEY CLUSTERED CREATE TABLE [dbo].[Customer]( [CustomerID] [int] IDENTITY(1,1) NOT NULL, [customerName] [varchar](30) NULL, [CustomerAddress] [varchar](30) NULL, [CustomerContact] [varchar](30) NULL, [VatNo] [int] NULL, CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED ) CREATE TABLE [dbo].[Cycle]( [CycleID] [int] IDENTITY(1,1) NOT NULL, [CycleNumber] [int] NULL, [StartDate] [date] NULL, [EndDate] [date] NULL ) ON [PRIMARY] CREATE TABLE [dbo].[Payments]( [PaymentID] [int] IDENTITY(1,1) NOT NULL, [Amount] [money] NULL, [PaymentDate] [date] NULL, [CustomerID] [int] NULL, PRIMARY KEY CLUSTERED Create table Invoices ( InvoiceID int IDENTITY(1,1), InvoiceNumber int, InvoiceDate date, BalanceBroughtForward money, OutstandingAmount money, CustomerID int, WaybillID int, PaymentID int, CycleID int PRIMARY KEY (InvoiceID), FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID), FOREIGN KEY (WaybillID) REFERENCES Waybills(WaybillID), FOREIGN KEY (PaymentID) REFERENCES Payments(PaymentID), FOREIGN KEY (CycleID) REFERENCES Cycle(CycleID) ) I want my sp to find all waybills for specific customer in a specific cycle with payments made from this client. All this data must then be added into the INVOICE table. Can someone please help me or show me on the right direction? create proc GenerateInvoice @StartDate date, @EndDate date, @Payee varchar(30) AS SELECT Waybills.WaybillNumber Waybills.SenderName, Waybills.SenderAddress, Waybills.SenderContact, Waybills.ReceiverName, Waybills.ReceiverAddress, Waybills.ReceiverContact, Waybills.UnitDescription, Waybills.UnitWeight, Waybills.DateReceived, Waybills.Payee, Payments.Amount, Payments.PaymentDate, Cycle.CycleNumber, Cycle.StartDate, Cycle.EndDate FROM Waybills CROSS JOIN Payments CROSS JOIN Cycle WHERE Waybills.ReceiverName = @Payee AND (Waybills.DateReceived BETWEEN (@StartDate) AND (@EndDate)) Insert Into Invoices (InvoiceNumber, InvoiceDate, BalanceBroughtForward, OutstandingAmount) Values (@InvoiceNumber, @InvoiceDate, @BalanceBroughtForward, @ OutstandingAmount) go

    Read the article

  • AND is better or using Internal "IF"

    - by BDotA
    In a situation like this:" if ((metadata != null) && (metadata.TypeEnum != VariantInfoMetadata.CellTypeEnum.Status)) do you recommend to keep the code as it is above or do you think it is better to make an internal "if" statement and brake that AND into two sections where "outer if" makes sure metadata is not null and inner if does the rest of the checking. I think this way will take care of possible null refrence exception if value of metadata gets null?

    Read the article

  • Using macro to check null values [migrated]

    - by poliron
    My C code contains many functions with pointers to different structs as parameteres which shouldn't be NULL pointers. To make my code more readable, I decided to replace this code: if(arg1==NULL || arg2==NULL || arg3==NULL...) { return SOME_ERROR; } With that macro: NULL_CHECK(arg1,arg2,...) How should I write it, if the number of args is unknown and they can point to different structs?(I work in C99)

    Read the article

  • Can a conforming C implementation #define NULL to be something wacky

    - by janks
    I'm asking because of the discussion that's been provoked in this thread: http://stackoverflow.com/questions/2597142/when-was-the-null-macro-not-0/2597232 Trying to have a serious back-and-forth discussion using comments under other people's replies is not easy or fun. So I'd like to hear what our C experts think without being restricted to 500 characters at a time. The C standard has precious few words to say about NULL and null pointer constants. There's only two relevant sections that I can find. First: 3.2.2.3 Pointers An integral constant expression with the value 0, or such an expression cast to type void * , is called a null pointer constant. If a null pointer constant is assigned to or compared for equality to a pointer, the constant is converted to a pointer of that type. Such a pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function. and second: 4.1.5 Common definitions <stddef.h> The macros are NULL which expands to an implementation-defined null pointer constant; The question is, can NULL expand to an implementation-defined null pointer constant that is different from the ones enumerated in 3.2.2.3? In particular, could it be defined as: #define NULL __builtin_magic_null_pointer Or even: #define NULL ((void*)-1) My reading of 3.2.2.3 is that it specifies that an integral constant expression of 0, and an integral constant expression of 0 cast to type void* must be among the forms of null pointer constant that the implementation recognizes, but that it isn't meant to be an exhaustive list. I believe that the implementation is free to recognize other source constructs as null pointer constants, so long as no other rules are broken. So for example, it is provable that #define NULL (-1) is not a legal definition, because in if (NULL) do_stuff(); do_stuff() must not be called, whereas with if (-1) do_stuff(); do_stuff() must be called; since they are equivalent, this cannot be a legal definition of NULL. But the standard says that integer-to-pointer conversions (and vice-versa) are implementation-defined, therefore it could define the conversion of -1 to a pointer as a conversion that produces a null pointer. In which case if ((void*)-1) would evaluate to false, and all would be well. So what do other people think? I'd ask for everybody to especially keep in mind the "as-if" rule described in 2.1.2.3 Program execution. It's huge and somewhat roundabout, so I won't paste it here, but it essentially says that an implementation merely has to produce the same observable side-effects as are required of the abstract machine described by the standard. It says that any optimizations, transformations, or whatever else the compiler wants to do to your program are perfectly legal so long as the observable side-effects of the program aren't changed by them. So if you are looking to prove that a particular definition of NULL cannot be legal, you'll need to come up with a program that can prove it. Either one like mine that blatantly breaks other clauses in the standard, or one that can legally detect whatever magic the compiler has to do to make the strange NULL definition work. Steve Jessop found an example of way for a program to detect that NULL isn't defined to be one of the two forms of null pointer constants in 3.2.2.3, which is to stringize the constant: #define stringize_helper(x) #x #define stringize(x) stringize_helper(x) Using this macro, one could puts(stringize(NULL)); and "detect" that NULL does not expand to one of the forms in 3.2.2.3. Is that enough to render other definitions illegal? I just don't know. Thanks!

    Read the article

  • Create a JSON Array using Java

    - by Ankur
    Hi I want to create a JSON array. I have tried using: JSONArray jArray = new JSONArray(); while(itr.hasNext()){ int objId = itr.next(); jArray.put(objId, odao.getObjectName(objId)); } results = jArray.toString(); Note: odao.getObjectName(objId) retrieves a name based on the "object Id" which is called objId However I get a very funny looking array like [null,null,null,"SomeValue",null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"AnotherValue",null,null,null,null,null,null,null,null,null,null,"SomethingElse","AnotherOne","LastOne"] With only "LastOne" being displayed when I retrieve it using jQuery. The Array SHould look like {["3":"SomeValue"],["40":"AnotherValue"],["23":"SomethingElse"],["9":"AnotherOne"],["1":"LastOne"]} The numbers aren't showing up at all for some reason in the array that I am getting

    Read the article

  • linq hierarchy problem

    - by Pratik
    I reterive a result from sql server as ProjectDetailID,ProjectID,ParentID,...,C1,C2,C3,... where C1 implies(=) companyOne, C2=CompanyTwo ... etc and dynamically can have 'n' companies For time being lets consider only 3 companies, So I get : ProjectDetailID,ProjectID,ParentID,C1,C2,C3 10,1,0,NULL,NULL,NULL 10,2,1,NULL,NULL,NULL 10,3,2,90,NULL,NULL 10,4,2,NULL,60,NULL 10,10,1,70,NULL,NULL 10,5,10,20,40,NULL 10,13,2,NULL,NULL,NULL I want from this following result using LINQ (C#) ProjectDetailID,ProjectID,ParentID,C1,C2,C3 10,1,0,180,100,NULL 10,2,1,90,60,NULL 10,3,2,90,NULL,NULL 10,4,2,NULL,60,NULL 10,10,1,90,40,NULL 10,5,10,20,40,NULL 10,13,2,NULL,NULL,NULL The problem is that at parent level i have null value for a company but at its child i have some value, which i keep on adding and have placed that in parent corresponding to that company only. I am not getting from where to start. Please share your ideas. And i am looking to do this in LINQ using C#

    Read the article

  • How to have multiple tables with multiple joins

    - by williamsdb
    I have three tables that I need to join together and get a combination of results. I have tried using left/right joins but they don't give the desired results. For example: Table 1 - STAFF id name 1 John 2 Fred Table 2 - STAFFMOBILERIGHTS id staffid mobilerightsid rights --this table is empty-- Table 3 - MOBILERIGHTS id rightname 1 Login 2 View and what I need is this as the result... id name id staffid mobilerightsid rights id rightname 1 John null null null null 1 login 1 John null null null null 2 View 2 Fred null null null null 1 login 2 Fred null null null null 2 View I have tried the following : SELECT * FROM STAFFMOBILERIGHTS SMR RIGHT JOIN STAFF STA ON STA.STAFFID = SMR.STAFFID RIGHT JOIN MOBILERIGHTS MRI ON MRI.ID = SMR.MOBILERIGHTSID But this only returns two rows as follows: id name id staffid mobilerightsid rights id rightname null null null null null null 1 login null null null null null null 2 View Can what I am trying to achieve be done and if so how? Thanks

    Read the article

  • Configure TV Capture card to not use external audio jack for TV audio output

    - by Adam D.
    I had this working with MythTV on Ubuntu 9.1. Then a power surge killed the motherboard. After replacing the motherboard, ram and cpu, the card does not produce any audio except through the output jack on the back of the card. I do not want to use a cable to go from the back of the card to the audio in on the built in sound card of the new mother board. FYI, the old motherboard did not have an on-board sound card. There was a separate audio card installed. There's some configuration that has to be done to have it work the same way again. I just have no idea where to start. This is regarding wintv hauppauge mythtv linux ubuntu 9.10 audio

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >